Ember计算升序排序

Ember Computed Sort ascending

本文关键字:排序 升序 计算 Ember      更新时间:2023-09-26

我正在尝试使用JSON API按日期对GitHub中的repos进行排序。

我正在使用Ember 1.13.7

我在jsbin中复制了我的案例,问题是我甚至看不到控制台错误来理解问题

这是应用的代码(在jsbin中有注释)

在我的控制器中

sortProperties: ['created_at:asc'],
sortedRepos: Ember.computed.sort('model', 'sortProperties')

在我的模板中

{{#each model.repos in sortedRepos}}
   <li>{{name}}</li>
   <li>{{format-date "LL" created_at}}</li>
{{/each}}

这里有什么错误?如何按日期(最新)对该型号进行排序?

p.s我正在使用一个助手模板{{format date}},带有moment js

这里是正在工作的jsbin

您排序错误的属性,它应该是model.repos而不是model,并且在jsbin中,您在ApplicationController而非IndexController 中创建了排序的计算属性

顺便说一句,一旦你将ember升级到2.x.x,你就应该使用

{{#each sortedRepos as |repo|}}
   <li>{{repo.name}}</li>
   <li>{{format-date "LL" repo.created_at}}</li>
{{/each}}