问题
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