可编辑文本 [蓝图JS] 如何访问新的文本值?反应



我正在使用 REACT 进行开发

我想使用蓝图JS可编辑文本来更新某些标签的文本。

http://blueprintjs.com/docs/#core/components/editable-text

当触发 onConfirm 时,我将如何在函数/请求中使用更新的文本?

假设我有一个与此类似的组件,其中构造函数为状态提供一些文本。

this.state = {
  text: this.props.text,
  updateText: ''
}

在渲染方法中,我渲染

<可编辑文本>

值=this.state.text

onConfirm={someFunction(xxx(}/>

其中"xxx"是可编辑文本字段的新文本值?

另外,当isEdit为真时,我将如何覆盖继承的样式?

您需要定义一个函数并将该函数作为 props 传递给组件。

class YourComponent extends React.Component {
    constructor(props) {
        super(props);
        this.handleChange = this.handleChange.bind(this);
    }
    handleChange = (value) => {
        // whatever you want to do for example, change the state 
        //this.setState({ value: value});
    };
    // and this is how you register the callback with the component 
    render () {
        return
            <EditableText
                value={this.state.text}
                onConfirm={this.handleChange} />
            />
    }
 }

最新更新