我浏览了real-js 文档,但找不到任何解释如何将对象推送到其父对象的数组属性的示例。
更清楚一点,我有一个Test
具有属性的 Schema data: {type: "data[]", default: []}
,但是我无法将任何data
对象推送到它。
这是我得到的错误。
属性必须是“数据”类型,得到 ([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;
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;
data
是 realm 的保留字,因为它已经有一个数据类型as data
。如果模式名称更改为其他名称,问题将得到解决。
Realm 支持以下基本类型:bool、int、float、double、string、data 和 date。
bool
属性映射到 JavaScriptboolean
值int
、float
和double
属性映射到 JavaScript 数字值。在内部int
并double
以 64 位float
存储,而以 32 位存储。string
属性映射到string
data
属性映射到ArrayBuffer
date
属性映射到Date
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句