AngularJS ngRepeat不尊重limitTo过滤器 [英] AngularJS ngRepeat not respecting limitTo filter

查看:255
本文介绍了AngularJS ngRepeat不尊重limitTo过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个列表项NG重复显示可用超市的物品。该项目采用检索到$ HTTP作为JSON和存储在$ scope.items和NG-重复工作正常显示所有的人。我的问题是,有这些项目的20,我想限制显示,就说3.我试图使用过滤器limitTo无果的数量。这里显示了显示的项目,但没有限制的截图,虽然过滤器被指定的:

I'm using ng-repeat on a list item to display available supermarket items. The items are retrieved using $http as JSON and stored in $scope.items, and ng-repeat is working fine to display all of them. My problem is that there are 20 of these items, and I want to limit the number displayed to, say, 3. I'm trying to use a limitTo filter to no avail. Here's a screenshot showing the displayed items but with no limit, despite the filter being specified:

http://i.imgur.com/4HiSdoG.png

我的HTML如下:

<span class="item-choices-choice pull-left">
    <ul>
         <li ng-repeat="choice in items.0 | limitTo:3">
             <img src="{[{ choice.ImagePath }]}" class="img-rounded" /> {[{ choice.Name }]} <strong>{[{ choice.Price }]}</strong>
         </li>
    </ul>
</span>

感谢您的帮助。

我会尽量解释一些事情。我已经重新分配{{{到[{在AngularJS,因为它与枝条否则冲突

I will try to explain a few more things: I've re-assigned {{ to {[{ in AngularJS as it conflicts with Twig otherwise.

项设置为在控制器的阵列:

items is set up as an array in the controller:

$scope.items = [];

下面是我从AJAX请求接收JSON:

Here's the JSON I receive from the AJAX request:

http://pastebin.com/ZN6ipRKQ

这JSON获得了$ HTTP PTED并分配给$间$ P $ scope.items [0]。 AngularJS似乎在任何情况下除了这个工作的罚款。

This JSON gets interpreted by $http and assigned to $scope.items[0]. AngularJS seems to be working fine in every case apart from this one.

推荐答案

我已经找到了问题。

看来,如果你json_en code的ArrayIterator在PHP中,它将连接code将其作为一个对象中的对象,而不是在一个数组的对象。这似乎导致在角工作不正常的limitTo(和其他)的过滤器的问题。

It seems, if you json_encode an ArrayIterator in PHP, it will encode it as an object within an object instead of an object in an array. This seems to cause the issue with the limitTo (and other) filters in Angular not working properly.

在ArrayIterator转化为正常的PHP数组和运行json_en code后,限制了作品精美绝伦。

After converting the ArrayIterator to a normal PHP array and running json_encode, the limiting works absolutely fine.

这篇关于AngularJS ngRepeat不尊重limitTo过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆