我正在尝试使用Ember.computed.sort,但无法弄清楚如何按belongsTo属性的名称进行排序。我已经在GOogle上工作了几个小时,找不到合适的组合。请帮助!
// my model
export default DS.Model.extend({
targetName: DS.attr(),
targetType: DS.attr(),
rack: DS.belongsTo('rack', {async: true}),
});
// this works:
export default Ember.Controller.extend({
sortedTargets: Ember.computed.sort('model', 'sortDefinition'),
sortDefinition: ['targetType']
});
// this doesn't work :
export default Ember.Controller.extend({
sortedTargets: Ember.computed.sort('model', 'sortDefinition'),
sortDefinition: ['rack.name']
});
答案 0 :(得分:2)
感谢@Lux对this thread的评论。这是一个适合我的解决方案。请注意模型上的Ember.computed.alias。
export default DS.Model.extend({
targetName: DS.attr(),
targetType: DS.attr(),
rack: DS.belongsTo('rack', {async: true}),
rackName: Ember.computed.alias('rack.name'),
});
// this works:
export default Ember.Controller.extend({
sortedTargets: Ember.computed.sort('model', 'sortDefinition'),
sortDefinition: ['targetType']
});
// this works too :) :
export default Ember.Controller.extend({
sortedTargets: Ember.computed.sort('model', 'sortDefinition'),
sortDefinition: ['rackName']
});