Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 以不同的方式在数据库中写入数据_Javascript_React Native - Fatal编程技术网

Javascript 以不同的方式在数据库中写入数据

Javascript 以不同的方式在数据库中写入数据,javascript,react-native,Javascript,React Native,我有一个通过蓝牙从外部设备读取数据的应用程序 例如: async setupNotifications1(device) { var timeagm = 0 this.subscriptionMonitor1 = device.monitorCharacteristicForService(service,this.AccGyrMg, (error, characteristic) => { const buf = Buffer.from(characteristic.v

我有一个通过蓝牙从外部设备读取数据的应用程序

例如:

async setupNotifications1(device) {
    var timeagm = 0
 this.subscriptionMonitor1 = device.monitorCharacteristicForService(service,this.AccGyrMg, (error, characteristic) => {
    const buf = Buffer.from(characteristic.value, "base64");
            const [...acc] = [2,4,6].map(index => buf.readInt16LE(index));
            this.setState(state => ({acc,array_acc_sx: [...state.array_acc_sx,[timeagm , acc ]]
            }));
//...
}}
然后我传递函数的这个值,并将这些数据写入数据库

我在数据库中的数据如下:(例如,这些数据每次都会更改,只有变量“time”相等)

我希望获得的数据如下:

我该怎么办

我还有另一个问题,你可以看到第一个值是时间。当我打印一行中的所有值时,我希望在1000(时间)后分离值

例如:

"AL": [
    [
      "0:-35:-70:-1041",

      "20:-36:-69:-1041",

      "40:-35:-70:-1041",

      "60:-36:-69:-1040",

      "80:-36:-69:-1040",

      .......

      "1000:-36:-68:-1041"

    ],

    [

      "1020:-36:-68:-1044",

      "1040:-36:-68:-1043",

      "1060:-36:-68:-1045",

    ........
]
非常感谢你的帮助!如果您需要澄清,我随时听候您的吩咐。

您可以尝试以下方法:

this.setState(state => ({acc,array_acc_sx: [...state.array_acc_sx,[timeagm , ...acc ].join(":")]
"AL": [
    [
      "0:-35:-70:-1041",

      "20:-36:-69:-1041",

      "40:-35:-70:-1041",

      "60:-36:-69:-1040",

      "80:-36:-69:-1040",

      .......

      "1000:-36:-68:-1041"

    ],

    [

      "1020:-36:-68:-1044",

      "1040:-36:-68:-1043",

      "1060:-36:-68:-1045",

    ........
]
this.setState(state => ({acc,array_acc_sx: [...state.array_acc_sx,[timeagm , ...acc ].join(":")]