如何从ReactJs中的updatehandler函数的文本框中获取最新值

时间:2019-02-20 07:19:55

标签: javascript reactjs

我有一个textBox,它将接受用户的输入,并将值添加到buildingNames数组中,该数组将显示在第二页中。该文本框已在项目中自定义和设计,无法更改。因此,以下组件是我正在使用的自定义文本框:

<CustomizedTextBox
            placeholder='Enter Building Name'
            id='AddBuilding'
            type='benchmarkPropertyName'
            maxLength='30'
            onTextUpdatedHandler={this.props.onClickAddBuildingTextBoxHandler.bind(this)}

          />

函数onClickAddBuildingTextBoxHandler()的定义如下所示:

onClickAddBuildingTextBoxHandler = (inputData) => { 
    let building={};
    building.buildingName=inputData.value;
    this.currentBuilding=inputData.value;
    this.setBuildingNames(building,this.props.propertyName);

  }

setBuildingNames()函数的定义如下:

 setBuildingNames = (buildingName, propertyName) => {
    let tempState = [...this.state.propertyList];
    let existingPropertyName = tempState.filter((property) => {
      return property.propertyName === propertyName;
    });
    if (_.isEmpty(existingPropertyName)) {
      let newProperty = {};
      newProperty.propertyName = propertyName;
      newProperty.buildingList = [];
      newProperty.buildingList.push(buildingName);
      tempState = [];
      tempState.push(newProperty);
    } else {
      // existingPropertyName[0].buildingList.push(buildingName);
      tempState.filter((property) => {
        if (property.propertyName === propertyName) {
          property.buildingList.push(buildingName);
        }
      });
    }
    this.setState({ ...this.state, propertyList: tempState });


  }

**

  • 问题:

**现在的问题是,因为我正在更新文本框的onTextUpdateHandler()函数中的状态,所以如果我在文本框中输入内容,则单击其他内容,然后返回并编辑文本再次使用不同的名称框,然后在文本框中先前添加的值也将被添加到buildingNames列表中。那么,如何从文本框中获取最新值并将其发送到下一页?

0 个答案:

没有答案