javascript - 如何将数组映射数据作为字符串发送到数据库?

标签 javascript android database reactjs react-native

美好的一天,我正在尝试使用数组映射将一些数据发送到我的数据库。我确实做到了,但问题是我必须将它作为 STRING 一起发送。

实际发生的是当我发送数据时,它就像数据库中的每一

因此,我的实际目标是在同一行同时发送两者。

enter image description here

这是我的代码

            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() }
           ....
     }
}

截图:

用户界面:

enter image description here

数据库:

enter image description here

最佳答案

试试这个代码:

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/

相关文章:

javascript - Next.js React 应用程序中未定义窗口

android - 应用程序在 android 中显示图像很慢

java - 在 Android 中从 JSON 对象对 JSON 数组进行排序?

android - ContentProvider android权限

mysql - 如何在每个 XX :50 Seconds? 上安排一个 MySQL 事件

javascript - 从外部按钮清除 Angular Bootstrap UI 选项卡集中与文本区域关联的 ng-model

javascript - 如何在 react js中显示和处理依赖于后端(Mongodb)中任务数组值的动态复选框?

sql-server - 导出到 PostgreSQL 时出现 SQL Server 导入和导出向导错误

javascript - 如何仅显示其中包含选定 <li> 的 <ul>,包括该父 ul 中的所有 <li>,而不仅仅是选定的 <li>?

android - 在不使用 webview 的情况下在 android 的 textview 中显示 html 表