【问题标题】:Adding filter button to sort entries添加过滤器按钮以对条目进行排序
【发布时间】:2014-08-05 06:42:18
【问题描述】:

所以我有这个查询可以为我提取数据:

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

我在我的手柄栏中有这段代码来显示它:

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

我正在考虑让我的 html 字段成为一个按钮,单击该按钮会对条目进行排序:

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

哪里有排序功能:

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

但是,我不断收到此错误:

错误:没有处理事件“sortBy”。

如果我单击该按钮,我不确定如何对条目进行排序?

【问题讨论】:

    标签: sorting ember.js filter javascript


    【解决方案1】:

    在每个循环中,提及itemController="ListsController" 并在ListsController 中编写sortBy 函数。

    基本上,您是在指示动作应该冒泡的控制器。

    【讨论】:

      【解决方案2】:

      正如@Ajey 提到的,您必须使用sortBy 操作创建一个ListsControllersortBy 已为 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'));
          }
        }
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-16
        • 1970-01-01
        • 2021-07-22
        • 2021-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多