我正在使用paho mqtt。我希望将数据发送到客户端通过的TextInput JSON数组但似乎我越来越不确定的数据如何通过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[]+'"}]
in sendMessage函数。有谁知道如何做到这一点?
任何人都可以帮助我。我仍然遇到这个问题。提前谢谢你。 – kkumber