嵌套ng重复限制不起作用

时间:2014-08-25 16:32:37

标签: javascript angularjs angularjs-ng-repeat ng-repeat

我目前遇到ng-repeat问题并限制了我视图中显示的元素数量。我想知道它是否与嵌套循环有关。这是代码:

<li style="cursor:pointer; margin:8px;" class="span3" ng-repeat="psp in preSplitPrompts" ng-click="selectRelatedSplitPanels($index)">

    <div ng-class="$first ? 'panelBackground' : 'altPanelBackground'" class="thumbnail splitPanel">
        <h3>{{ (psp.promptname) ? psp.promptname : "No Name From API" }}</h3>
        <hr>
        <h2 ng-repeat="postsplit in psp.postSplit | limitTo: 1">{{ postsplit.metrics.preSplitTotalCount ? postsplit.metrics.preSplitTotalCount : 0 }}</h2>
        <p>Visits</p>
    </div>

</li>

我尝试通过limitTo:1限制列表项,并且工作正常。只有在试图限制后分裂时才会这样。谢谢你的帮助。

修改

此代码有效:

<li style="cursor:pointer; margin:8px;" class="span3" ng-repeat="psp in preSplitPrompts | limitTo: 1" ng-click="selectRelatedSplitPanels($index)">

    <div ng-class="$first ? 'panelBackground' : 'altPanelBackground'" class="thumbnail splitPanel">
        <h3>{{ (psp.promptname) ? psp.promptname : "No Name From API" }}</h3>
        <hr>
        <h2 ng-repeat="postsplit in psp.postSplit">{{ postsplit.metrics.preSplitTotalCount ? postsplit.metrics.preSplitTotalCount : 0 }}</h2>
        <p>Visits</p>
    </div>

</li>

这是数据对象:

preSplitPrompts data object

1 个答案:

答案 0 :(得分:1)

试试这个:

ng-class="{$first ? 'panelBackground' : 'altPanelBackground'}"