[英]angularjs limitTo filter not working with odd json array
I have an odd json array that I can ng-repeat just fine, but I'm having trouble limiting this list with the limitTo filter. 我有一个奇怪的json数组,可以ng-repeat很好,但是我很难用limitTo过滤器限制此列表。 I'm getting the json object with an http call so I can't change how the object is formed on the back-end.
我正在通过http调用获取json对象,因此无法更改对象在后端的形成方式。
HTML: HTML:
<div ng-controller="myCtrl">
<div ng-repeat="school in schoolList | limitTo:2">
{{school.school_name}}
</div>
</div>
JSON: JSON:
{"0":{"school_name":"FAKE ELEMENTARY"},
"1":{"school_name":"CENTRAL HIGH"},
"2":{"school_name":"OAK RIDGE ELEMENTARY"},
"3":{"school_name":"PINE MEADOW ELEMENTARY"},
"4":{"school_name":"AMERICAN MIDDLE"},
"5":{"school_name":"BIG SENIOR HIGH"},
"6":{"school_name":"ST FRANCIS ELEMENTARY SCHOOL"}
Here is the jsfiddle 这是jsfiddle
My first thought is that I could somehow use $index but I haven't had any luck thus far. 我的第一个想法是,我可以某种方式使用$ index,但到目前为止我还没有任何运气。 Any help would be appreciated.
任何帮助,将不胜感激。 I apologize in advanced if this has already been answered but I've been searching for a few days without finding anything helpful.
如果已经回答了高级问题,我深表歉意,但是我已经搜索了几天,没有发现任何帮助。 Thanks.
谢谢。
From the angular source the first check is: 从角度源中,第一个检查是:
if (!isArray(input) && !isString(input)) return input;
So you will have to convert that data to an array, see working fiddle here: http://jsfiddle.net/Nu7rZ/103/ 因此,您将不得不将数据转换为数组,请参见此处的工作提琴: http : //jsfiddle.net/Nu7rZ/103/
angular source link: https://github.com/angular/angular.js/blob/master/src/ng/filter/limitTo.js#L3 角度源链接: https : //github.com/angular/angular.js/blob/master/src/ng/filter/limitTo.js#L3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.