get data from emberjs store.find

…衆ロ難τιáo~ 提交于 2019-12-10 23:55:56

问题


I have a route with model person:

export default Ember.Route.extend({
  model: function(){
    return this.store.findAll('person');
  }
});

I want to modify the data in this model in my controller:

export default Ember.Controller.extend({
  actions:{
    justLog: function(){
      this.get('model') // ???
    }
  }
});

but this.get('model'); returns Class {store: Class, isLoaded: true, manager: Class, isUpdating: false, __ember1463955537869: "ember357"…} and i cant get the data out of it.


回答1:


You have two choices, the first one:

this.get('model').forEach(function(element){
  element.get('propertyName');
})

The second one:

this.get('model').map(function(element){
  return element.get('propertyName');
})

Remeber that the map functor returns a brand new array.

To modify the values you should use .set('propertyName', value); function.



来源:https://stackoverflow.com/questions/37380384/get-data-from-emberjs-store-find

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!