我正在使用paho mqtt。我想通过textinput将数据作为json数组发送到客户端,但似乎我得到了未定义的数据
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
constructor(props) {
super(props);
this.state = {
listofItems: [],
text: '',
text1: '',
}}
_addTask () {
const listofItems = [...this.state.listofItems, this.state.text, this.state.text1];
this.setState({
listofItems: listofItems,
text: '',
text1: '',
});
this._changeTextInputValue('');
}
_changeTextInputValue (text) {
this.setState({
text
});
}
_changeTextInputValue1 (text1) {
this.setState({
text1
});
}
static _renderRowData (rowData) {
return (
<Text>{ rowData }</Text>
)
}
这是文字输入
<TextInput autoCorrect={ false }
onChangeText={ (text) => this._changeTextInputValue(text) }
onSubmitEditing = {() => this.itemcodeDesc.focus()}
style={{backgroundColor:'#ddd'}}
value={ this.state.text }
/>
<TextInput
autoCorrect={ false }
onChangeText={ (text1) => this._changeTextInputValue1(text1) }
onSubmitEditing={ () => this._addTask() }
returnKeyType={ 'done' }
ref={(input) => this.itemcodeDesc = input}
style={{backgroundColor:'#ddd'}}
value={ this.state.text1 }
/>
按钮:
<TouchableHighlight style={styles.button} onPress={this.sendMessage} underlayColor="transparent">
<Text style={styles.buttonText}>NEXT</Text>
</TouchableHighlight>
但是当我调用这个
时,我无法获得json格式的项目数组"items": [{"itemcode":"'+this.state.listofItems[]+'"}]
在sendMessage函数中。有谁知道怎么做?
答案 0 :(得分:0)
我想它应该是this.state.listofItems
而不是this.state.listofItems[]
。
希望这有帮助