简体   繁体   English

添加过滤器按钮对条目进行排序

[英]Adding filter button to sort entries

So I have this query that pulls the data for me: 所以我有这个查询为我拉数据:

App.ListRoute = Ember.Route.extend({
model: function() { return $.getJSON('php/getlines.php'); }});

And I have in my handle bar this code to display it: 我在手柄栏中有以下代码可以显示它:

<tbody>
{{#each content}}
{{view App.lineItem contextBinding="this"}}
{{/each}}
</tbody>

I was thinking of making my html fields a button which when clicked would sort the entries: 我正在考虑将我的html字段设置为一个按钮,单击该按钮将对条目进行排序:

<th class="center"{{action 'sortBy' 'invoice'}}>Invoice</td>

where there is a sort by function: 其中按功能排序:

sortBy: function(property) {
  this.set('sortProperties', [property]);
  this.set('sortAscending', !this.get('sortAscending'));
 }

However, I keep getting this error: 但是,我不断收到此错误:

Error: Nothing handled the event 'sortBy'. 错误:没有任何处理事件“ sortBy”。

I am not sure how I can have the entries sorted if I click that button? 我不确定如果单击该按钮如何对条目进行排序?

in the each loop, mention itemController="ListsController" and write the sortBy function in the ListsController. 在每个循环中,提及itemController="ListsController"并在sortBy中编写sortBy函数。

Bascially with this you are indicating which controller the action should bubble up. 基本上以此为基础,您可以指示动作应该冒出哪个控制器。

As @Ajey mentions, you have to create a ListsController with a sortBy action. 如@Ajey所述,您必须使用sortBy操作创建一个ListsController sortBy is already defined for ArrayController (see http://emberjs.com/api/classes/Ember.ArrayController.html#method_sortBy ) but I'm pretty sure adding an action of the same name won't override it. 已经为sortBy定义了ArrayController (请参阅http://emberjs.com/api/classes/Ember.ArrayController.html#method_sortBy ),但是我敢肯定,添加具有相同名称的动作不会覆盖它。

App.ListsController = Ember.ArrayController.extend({
  actions: {
    sortBy: function(property) {
      this.set('sortProperties', [property]);
      this.set('sortAscending', !this.get('sortAscending'));
    }
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM