组件正在将未定义类型的非受控输入更改为受控输入

eh57zj3b  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(144)

警告:组件正在将未定义类型的非受控输入更改为受控输入。输入元件不应从非受控切换到受控(反之亦然)。在组件的使用寿命内,决定使用受控或非受控输入元件。更多信息:fb.me/react-controlled-components

onChange = event => {
      const{name,value}=event.target;
        this.setState({
            [name]:value
        });
    };

    showEditDialog() {
        this.setState({
            ilac: {
                id: this.selectedIlac.id,
                ilacAdi: this.selectedIlac.ilacAdi
            }
        });
    }

    save = async event => {
        event.preventDefault();

        const ilac = {
            id: this.state.id,
            ilacAdi: this.state.ilacAdi
        }
        try {
            const response = await this.ilacService.save(ilac);
        } catch (error) {

        }

        this.ilacService.getAll().then(data => this.setState({ ilac: data }))
        this.state.selectedIlac.ilacAdi = '';
        // this.setState({value:  this.state.selectedIlac.ilacAdi});
    }

    put = async event => {
        event.preventDefault();

        const ilac = {
            id: this.state.selectedIlac.id,
            ilacAdi: this.state.selectedIlac.ilacAdi
        }
        try {
            const response = await this.ilacService.put(ilac);
        } catch (error) {

        }

        this.ilacService.getAll().then(data => this.setState({ ilac: data }))
        this.state.selectedIlac.ilacAdi = '';
        // this.setState({value:  this.state.selectedIlac.ilacAdi});
    }

    render() {
        return (
            <Panel style={{ width: "60%", margin: "0 auto", marginTop: "40px" }} header="İlaç Listesi">
                <div className="content-section implementation" style={{ marginBottom: "200px" }}>
                    <div className="p-inputgroup">
                        <InputText value={this.state.selectedIlac.ilacAdi} name="ilacAdi" onChange={this.onChange} placeholder="İlaçAdı" />
                    </div>
                    <br></br>
                    <div>
                        <Button onClick={this.save} label="Save" icon="pi pi-plus" iconPos="right" />
                        <Button onClick={this.put} className="p-button-warning" label="Update" icon="pi pi-check" iconPos="right" />
                        <Button className="p-button-danger" label="Delete" icon="pi pi-trash" iconPos="right" />
                    </div>
                </div>

            {/* paginator={true} rows="10" */}
            <DataTable onClick={this.showEditDialog} value={this.state.ilac} selectionMode="single" selection={this.state.selectedIlac} onSelectionChange={e => this.setState({ selectedIlac: e.value })} >
                <Column field="id" header="ID"></Column>
                <Column field="ilacAdi" header="İLAÇ ADI"></Column>
            </DataTable>
        </Panel>
    );
}`

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题