我正在使用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