Sorting 添加筛选按钮以对条目进行排序
因此,我有一个查询为我提取数据:Sorting 添加筛选按钮以对条目进行排序,sorting,ember.js,filter,javascript,Sorting,Ember.js,Filter,Javascript,因此,我有一个查询为我提取数据: App.ListRoute = Ember.Route.extend({ model: function() { return $.getJSON('php/getlines.php'); }}); 我的手柄上有一个显示代码: <tbody> {{#each content}} {{view App.lineItem contextBinding="this"}} {{/each}} </tbody> 然而,我不断地发现这个错误: 错
App.ListRoute = Ember.Route.extend({
model: function() { return $.getJSON('php/getlines.php'); }});
我的手柄上有一个显示代码:
<tbody>
{{#each content}}
{{view App.lineItem contextBinding="this"}}
{{/each}}
</tbody>
然而,我不断地发现这个错误:
错误:未处理事件“sortBy”
如果单击该按钮,我不确定如何对条目进行排序?在每个循环中,提到itemController=ListsController并在ListsController中编写sortBy函数
最重要的是,您可以指示操作应该出现在哪个控制器上。正如@Ajey提到的,您必须创建一个带有sortBy操作的ListsController。sortBy已经为ArrayController定义,请参见,但我很确定添加相同名称的操作不会覆盖它
App.ListsController = Ember.ArrayController.extend({
actions: {
sortBy: function(property) {
this.set('sortProperties', [property]);
this.set('sortAscending', !this.get('sortAscending'));
}
}
});
sortBy: function(property) {
this.set('sortProperties', [property]);
this.set('sortAscending', !this.get('sortAscending'));
}
App.ListsController = Ember.ArrayController.extend({
actions: {
sortBy: function(property) {
this.set('sortProperties', [property]);
this.set('sortAscending', !this.get('sortAscending'));
}
}
});