【问题标题】:SharePoint react TextField onChanged errorSharePoint 反应 TextField onChanged 错误
【发布时间】:2020-09-23 00:58:13
【问题描述】:

当“gulp serve”我的 SharePoint 扩展解决方案时,我收到此错误

类型{标签:字符串;要求:真;名称:字符串;默认值:字符串; onChanged: (text: string) => void; } 不可分配给类型 'IntrinsicAttributes & ITextFieldProps & { children?: ReactNode; }'。 类型'IntrinsicAttributes & ITextFieldProps & { children?: ReactNode; 上不存在属性'onChanged' }.ts(2322)

我正在使用:

@microsoft/generator-sharepoint@1.10.0 gulp@4.0.2 npm@6.14.4 哟@3.1.1

SendEMailDialogContent.tsx 文件代码如下:

import * as React from 'react';
import {
    TextField,
    PrimaryButton,
    Button,
    DialogFooter,
    DialogContent,
    Spinner,
    SpinnerSize
} from 'office-ui-fabric-react';
import { ISendEMailDialogContentProps } from './ISendEMailDialogContentProps';
import { EMailProperties, EMailAttachment } from '../models';
import { ISendEMailDialogContentState } from './ISendEMailDialogContentState';

export class SendEMailDialogContent extends React.Component<ISendEMailDialogContentProps, ISendEMailDialogContentState> {
    private _eMailProperties: EMailProperties;

    constructor(props) {
        super(props);
        this.state = {
            isLoading: false
        };
        this._eMailProperties = this.props.eMailProperties;        
        this._onChangedTo = this._onChangedTo.bind(this);
        this._onChangedSubject = this._onChangedSubject.bind(this);
        this._onChangedBody = this._onChangedBody.bind(this);
        this._submit = this._submit.bind(this);
    }

    public render(): JSX.Element {
        var getDialogContent = () => {
            if (this.state.isLoading) {
                return (
                    <Spinner size={SpinnerSize.large} label="loading..." ariaLive="assertive" />
                );
            }
            else {
                return (
                    <div>
                        <TextField label='To' required={true} name="To" defaultValue={this._eMailProperties.To} onChanged={this._onChangedTo} />
                        <TextField label='Subject' required={true} defaultValue={this._eMailProperties.Subject} onChanged={this._onChangedSubject} />
                        <TextField label='Body' required={true} multiline defaultValue={this._eMailProperties.Body} onChanged={this._onChangedBody} />

                        <DialogFooter>
                            <Button text='Cancel' title='Cancel' onClick={this.props.close} />
                            <PrimaryButton text='OK' title='OK' onClick={this._submit} />
                        </DialogFooter>
                    </div>);
            }
        };
        // UI
        return <DialogContent
            title='Send E-Mail Details'
            subText=''
            onDismiss={this.props.close}
            showCloseButton={true}
        >
            {getDialogContent()}
        </DialogContent>;
    }

    private _onChangedSubject(text: string) {
        this._eMailProperties.Subject = text;
    }    

    private _onChangedTo(text: string) {
        this._eMailProperties.To = text;
    }    

    private _onChangedBody(text: string) {
        this._eMailProperties.Body = text;
    }

错误与TextField有关 - onChanged={this._onChangedxxxxx}

【问题讨论】:

    标签: sharepoint-online spfx office-ui-fabric-react


    【解决方案1】:

    根据使用的office-ui-fabric-react 的版本,这个回调现在很可能被称为onChange 而不是onChanged

    除了重命名之外,onChange 期望第一个参数是一个反应事件,因此您需要更改您的 onChanged* 方法以期望更多参数(并且他们可以随意忽略它)。

    相关文档:https://developer.microsoft.com/en-us/fluentui#/controls/web/textfield#implementation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多