v1.3.0-beta.13之后,使用orderBy的ng-repeat对我来说无法工作。

4

有人注意到在以下配置中使用ng-repeat时出现问题吗:

<div ng-repeat="row in home.grid.view = (home.grid.data | orderBy:ctrl.contentOrderBy[ctrl.configService.admin.contentOrderBy].key:ctrl.configService.admin.contentSortDirection)">

这是我的contentOrderBy对象:

[{"id":0,"name":"CId","key":"contentId"},
 {"id":1,"name":"Modified By","key":"modifiedBy"},
 {"id":2,"name":"Modified Date","key":"modified"},
 {"id":3,"name":"Status","key":"contentStatusId"},
 {"id":4,"name":"Status > Type","key":["contentStatusId","contentTypeId"]}] 

ctrl.configService.admin.contentSortDirection有两个值:0或1。

我的问题是当我尝试更改configService.admin.contentSortDirection时:

  • @license AngularJS v1.3.0-beta.8 - 可行
  • AngularJS v1.3.0-beta.12 - 可行
  • AngularJS v1.3.0-beta.13 - 可行
  • AngularJS v1.3.0-beta.14 - 无法改变方向
  • @license AngularJS v1.3.0-rc.5 - 无法改变方向
  • @license AngularJS v1.3.0 - 无法改变方向

我已经检查了最新的文档,除非我弄错了,否则我找不到如何进行 orderBy 的任何内容,而我认为在以前的文档中曾经出现过。

如果其他人知道有效的方法,请提供任何建议。我也想知道为什么ng-repeat文档似乎有点缺乏。


你看到了变更日志吗? - Rahil Wazir
是的,我查了一下,但没有找到任何解释为什么在 beta 13 之后,超过 1,000 个测试中只有这个功能停止工作。 - Samantha J T Star
1个回答

6

将这行代码改为:

<div ng-repeat="row in home.grid.view = (home.grid.data | orderBy:ctrl.contentOrderBy[ctrl.configService.admin.contentOrderBy].key:ctrl.configService.admin.contentSortDirection)">

to:

<div ng-repeat="row in home.grid.view = (home.grid.data | orderBy:ctrl.contentOrderBy[ctrl.configService.admin.contentOrderBy].key:ctrl.configService.admin.contentSortDirection == 1)">

哈里什的想法是正确的,但他设置反转参数的方式完全错误:

reverse=order.dir === 1

没有要求添加"reverse="。

您的问题是由Beta 14版本中的此更改引起的:

fix(core): drop the toBoolean function
So far Angular have used the toBoolean function to decide if the parsed value
is truthy. The function made more values falsy than regular JavaScript would,
e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs
when backend sends a non-empty string with one of these values and something
suddenly hides in the application

Thanks to lgalfaso for test ideas.

BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer
treated as falsy. Only JavaScript falsy values are now treated as falsy by the
expression parser; there are six of them: false, null, undefined, NaN, 0 and "".

Closes #3969
Closes #4277
Closes #7960

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接