简体   繁体   中英

How can you manipulate db content thats returned from findAll function in model hook of ember?

The return value of findAll is an unknown mixin. eg . in router xyz.js

model(){
a = this.store.findAll('food-track');
return a
}

How do we manipulate a or extract data from a in model itself like

model(){
a = this.store.findAll('food-track');
some_data = a['_id'];
some_more_data = a['name'];
return some_more_data
}

But then a isn't in a format that I expected it to be in and I wasn't able to perform any function like this? Btw the data is taken from couch/pouchdb.

findAll returns Promise which will be resolved to RecordArray which extends ArrayProxy so you can use all the methods available in ArrayProxy.

model(){
 return this.store.findAll('food-track').then((result) => {
  //here you can forEach method to iterate and to filter use filterBy
  //Use objectAt(index) to retrieve object and use get and set 
  //dont forget to the return transformed result.
  return result;
});
}

I agree with kumkanillam answer: findAll will return an array so you'll have to iterate over it.

Also, depending on what your needs are, you can use computed properties to manipulate your model property as well. Here are the docs from Ember

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM