美好的一天,我正在尝试使用数组映射将一些数据发送到我的数据库。我确实做到了,但问题是我必须将它作为 STRING 一起发送。
实际发生的是当我发送数据时,它就像数据库中的每一行。
因此,我的实际目标是在同一行同时发送两者。
这是我的代码
fetch('http://192.168.254.***:****/SendOrder/Send',
{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
tbl_id: this.state.Checked_ORDER_NO,
.... // other data
})
}).then(res => res.json())
.then((responseJson) => {
console.log(responseJson);
})
.catch(error => console.error('Error:', error))
For_table_No() {
return this.state.CHECKED_Data.map((item) => {
return (
<View>
<View key={key}>
<Text>Merged Table: { item.Checked }</Text>
</View>
</View>
)
})
}
render() {
return{
....
{ this.For_table_No() }
....
}
}
截图:
用户界面:
数据库:
最佳答案
试试这个代码:
state = {
data: ''
}
yourfunc = () => {
fetch('your url', {
method: "GET",
headers: {
"Content-Type": "application/json",
//other headers
}
})
.then(res => res.json())
.then(result => {
result.data.forEach(item => {
let olddata = this.state.data
this.setState(prevState => ({
data: `${item.id}, ${olddata}`
}))
})
})
.catch(err => console.log(err))
}
render() {
return (
<View style={{ flex: 1, justifyContent: 'center' }}>
<Text>{this.state.data}</Text>
</View>
)
}
您可以根据自己的逻辑进行自定义,希望对您有所帮助:)
已编辑:
等等,抱歉,我没明白真正的问题是,我想你想在行中显示数据。
关于javascript - 如何将数组映射数据作为字符串发送到数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54389402/