companies
和ships
都有name
属性。但我不明白如何在此代码中使用sortProperties
:
应用/控制器/ index.js
import Ember from 'ember';
export default Ember.Controller.extend({
selectedCompany: null,
companies: function(){
var model = this.get('model.companies');
return model;
}.property(),
ships: function(){
var model = this.get('model.ships');
return model;
}.property()
});
应用/路由/ index.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return {
companies: this.store.find('company'),
ships: this.store.find('ship')
};
}
});
如何按companies
属性对ships
和name
进行排序?
答案 0 :(得分:1)
使用sortBy
功能。像这样:
import Ember from 'ember';
export default Ember.Controller.extend({
selectedCompany: null,
sortedCompanies: function(){
var model = this.get('model.companies').sortBy('name');
return model;
}.property('model.companies'),
sortedShips: function(){
var model = this.get('model.ships').sortBy('name');
return model;
}.property('model.ships')
});
请记住将您观察到的属性放入.property()
,否则当模型更改时,它的缓存不会失效。