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'評論'在你的模板。 –