说明
我通过了
realm-js
documentation
找不到任何解释如何将对象推入其父对象的数组属性的示例。
更清楚一点,我有一个模式
Test
data: {type: "data[]", default: []}
data
反对它。
错误:
这是我得到的错误。
属性的类型必须为'data',got([object RealmObject])
我尝试的是:
这就是我所尝试的:
this.realm.write(()=>{
const dataObj = this.realm.create('data', data);
this.user.test.data.push(dataObj);
})
我做错什么了?
我也试图直接推送数据,但我得到了一个类似的错误。
测试架构:
class Test{
}
Test.schema = {
name: "test",
primaryKey: "id",
properties: {
id: "string",
start: "date?",
duration: "int", //in seconds
capsule_id: "string",
creation: "date",
status: "int",
height: "float",
weight: "float",
time_of_evolution: "string",
treatment: "bool",
data: {type: "data[]", default: []},
symptoms: {type: "symptom[]", default: []},
meals: {type: "meal[]", default: []},
device: "device?",
ph11: "int?",
ph71: "int?",
ph12: "int?",
ph72: "int?",
cardinal_symptoms: {type: "cardinal_symptom[]", default: []},
}
};
export default Test;
DeviceData架构
class DeviceData{}
DeviceData.schema = {
name: 'data',
primaryKey: "timestamp", //check to see if this is a good idea
properties: {
ph1: 'int',
ph2: 'int',
x: 'int',
y: 'int',
z: 'int',
timestamp: 'int',
raw: 'string' //base64, incase something went wrong
}
};
export default DeviceData;