【发布时间】:2018-04-25 12:56:41
【问题描述】:
我已经尝试了很多方法来让它发挥作用。
我的构造函数中有以下 2 个统计数据:
constructor(props) {
super(props);
this.state = {
newArray: [],
dataStorage: [],
};
}
然后我有一个函数来处理来自 TextInputs 的参数。我正在创建一个新数组来添加数据,然后我想将其添加到现有数组中。
submitHandler(inputValue, inputIdentifier) {
console.log('inside the submitHandler');
var newArray = [];
newArray.push({
value: inputValue,
identificer: inputIdentifier.item
});
this.setState({newArray: newArray})
let dataStorage = [this.state.newArray, ...this.state.dictionaryForAddedItems]
this.setState({dataStorage: dataStorage})
console.log('her is was inside the newArray' + JSON.stringify(newArray));
console.log('her is was inside the state.dictionaryForAddedItems' + JSON.stringify(this.state.dataStorage));
我的日志是这样的: Log in debug looks like this
【问题讨论】:
标签: arrays reactjs react-native