0
我已经看过几个例子,但还没有能够进行反向排序,因此新生成的对象处于顶部。通过ember上的时间戳对数据进行排序
我的可排序项目在组件中,我不认为我正确传递sortProperties & sortAscending。
lavender.js:
export default Ember.Controller.extend({
needs: ['application'],
sortProperties: ['timestamp'],
sortAscending: false
});
lavender.hbs
{{#each model.comment as |comment|}}
{{comment-thread message=comment.message user=comment.user timestamp=comment.timestamp sortProperties=sortProperties sortAscending=sortAscending}}
{{/each}}
comment.js
export default DS.Model.extend({
message: DS.attr('string'),
timestamp: DS.attr('date'),
user: DS.belongsTo('user', {async: true}),
todo: DS.belongsTo('todo', {async: true}),
});
todo.js(型号为lavender.js)
export default DS.Model.extend({
title: DS.attr('string'),
isCompleted: DS.attr('boolean', {defaultValue: false}),
detail: DS.attr('string', {defaultValue: "add details.."}),
comment: DS.hasMany('comment', {async: true}),
});
必须有我没有看到的东西..谢谢!
谢谢!根据您的建议,我选择实施Ember.computed宏。我是新来的烬,所以我有一些基本的问题。 'timestamp:desc'代表什么? 我是否会替换Ember.computed.sort('comments')的Ember.computed.sort('model')? – sunoceansand
另外,如何在模板中的ember.computed上重复评论? – sunoceansand
1)'timetamp:desc'表示你想按'timestamp'属性降序排序。 2)我在那里放了'model',但是我看到你遍历'model.comment',所以'model.comment'应该在那里(如果这是一个模型数组,我不知道你没有给出代码模型)。 3)评论被排序'model.comment',所以你迭代iver'评论'在你的模板。 –