简体   繁体   English

Realm对象列表函数未定义,即使定义了对象并填充了列表

[英]Realm object list functions are undefined, even though object is defined and list is populated

Trying to push a new int into an int realm list. 尝试将新int推入int领域列表。 I can get the Realm object, I can print it and when I print the object it shows the list with it's content, I can use Realm Studio to edit, add numbers to the list, etc.. But when I try to call any methods form the list it says it is undefined. 我可以获取Realm对象,我可以打印它,当我打印对象时,它显示带有它内容的列表,我可以使用Realm Studio进行编辑,将数字添加到列表中等等。但是当我尝试调用任何方法时从列表中可以看出它是未定义的。

Have tried async, await, then, though it was a synchronization issue, but doesn't seem like it. 尝试了异步,等待,然后,虽然这是一个同步问题,但似乎不是这样。

The code below is similar to mine, but edited to hide the original names, etc, and does not have all the properties from the original, but it does not change the behave for the specific list I am trying to edit. 下面的代码与我的类似,但编辑后隐藏原始名称等,并且没有原始属性的所有属性,但它不会更改我尝试编辑的特定列表的行为。 Everything else works fine. 其他一切都很好。 I have an schema like 我有一个类似的架构

let mySchema={
    name:'MySchema',
    properties:{
        my_schema_id: 'string',
        numbers: 'int[]'
    }

The function to create a new object is 创建新对象的功能是

Realm.open({schema: [mySchema]})
  .then(realm => {
    realm.write(() => {

        realm.create('MySchema', {my_schema_id: `${my_schema_id}`, numbers: [parseInt(number, 10)]});
      });

I try to add a number with: 我尝试添加一个数字:

Realm.open({schema: [mySchema]})
    .then((realm) => {
    let fetchedSchema = realm.objects('MySchema').filtered(`my_schema_id ="${my_schema_id}"`);

console.log(fetchedSchema);
    realm.write(()=>{
        fetchedSchema.numbers.push(parseInt(number, 10));
    });

And it gives an error: 它给出了一个错误:

(node:73249) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined

I expected to push the item to the list, or to be able to call the list functions. 我希望将项目推送到列表,或者能够调用列表函数。 Instead, when I try to use the list it shows as undefined even though I can see it and it's content when I print the object... 相反,当我尝试使用列表时,它显示为undefined即使我可以看到它,当我打印对象时它是内容...

Found a solution. 找到了解决方案。 Querying let fetchedSchema = realm.objects('MySchema').filtered( my_schema_id ="${my_schema_id}" ); 查询let fetchedSchema = realm.objects('MySchema').filtered( my_schema_id =“$ {my_schema_id}” ); actually returns an array of elements, so I just had to select the first with [0] at the end 实际上返回一个元素数组,所以我只需要在结尾选择第一个[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使对象已定义,也无法读取“未定义”的属性! [反应] - Cannot read property of “undefined” even though the object IS defined! [React] 即使属性存在,js对象也返回undefined - js object returns undefined even though property is there 即使已初始化,对象变量也未定义 - Object variable is undefined even though it's initialised 如何列出javascript对象的函数/方法? (它甚至可能吗?) - How to list the functions/methods of a javascript object? (Is it even possible?) javascript 对象被定义然后它是未定义的。 对象和函数共享同一个对象 - javascript object is defined then it is undefined. The object and functions share the same object 即使该字段不为空,Parse.Object.get()仍返回未定义 - Parse.Object.get() returns Undefined even though the field is not empty 对象属性返回 undefined 即使它存在 JavaScript - object property returns undefined even though it exists JavaScript JS 说 object 是未定义的,即使它显示在 console.log 中 - JS says an object is undefined even though it shows with console.log JSON对象即使存在也返回未定义状态(NASA API和React) - JSON object returning undefined even though it is there(NASA API and React) 即使对象prop存在也返回undefined-JS - Returns undefined on a object prop even though it exists-JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM