Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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
React native 无法从领域对象检索数据_React Native_Realm - Fatal编程技术网

React native 无法从领域对象检索数据

React native 无法从领域对象检索数据,react-native,realm,React Native,Realm,我想知道如何从包含模式数据的领域对象获取数据 db.js-Page,其中定义了领域数据库 .......................................... export const tableProjectSchema = { name: TABLE_PROJECT, primaryKey: 'id', indexed:'true', properties: { id: 'int', project

我想知道如何从包含模式数据的领域对象获取数据

db.js-Page,其中定义了领域数据库

  ..........................................

  export const tableProjectSchema = {

   name: TABLE_PROJECT,

   primaryKey: 'id',

   indexed:'true',

   properties: {

        id: 'int',

        project_id: 'int',

        project_name: 'string'
    }

};

 ...................................................

 export const  getProject = newProject => new Promise((resolve, reject) =>

 {  

 Realm.open(databaseOptions).then(realm => {

 realm.readOnly(() => {

 let allProjects = realm.objects(TABLE_PROJECT);

 resolve(allProjects);

});

}).catch(

  (error) => reject(error));

});
sample.js-此处导入了db.js并从此页面调用函数getProject()

render() {

    let Projects=Database.getProject();

    console.log("table object"+Projects);
    ...................
    }
我想从sample.js中的对象“Projects”获取项目名称

注销: 表对象[对象对象]

修改了getProject()方法

export const  getProject = newProject => new Promise((resolve, reject) =>

 {  

     Realm.open(databaseOptions).then(realm => {

     let allProjects = realm.objects(TABLE_PROJECT);

     resolve(allProjects);

    }).catch(

    (error) => reject(error));

  });
使用从对象获取数据

 Database.getProject().then((projects) => 
 console.log(projects.forEach(project => console.log(`Project name: 
 ${project.project_name}`)))).catch((error) => { console.log(`Error in 
 fetching projects: ${error}`) });

尝试console.log(“table object”,Projects)@Kranthi Kumar Julakanti这是我在JSON.stringify该对象时得到的结果。但是,这不能满足我的需要。我想显示该对象的项目名称。如果项目是数组,请为(i=0,i@KranthiKumarJulakanti我试过了,但没有结果。顺便说一句,我得到了答案。谢谢你的努力,我真的很感激。