0
<div ng-app="streams">
    <div ng-controller="streamsList">
        <ul class="streamsList">
            <li class="streamsListItem" ng-repeat="(streamer, viewers) in streamerItems | limitTo:5">
                <h2>{{streamer | uppercase}}</h2>
                <span>{{viewers}}</span>
            </li>
        </ul>
    </div>
</div>

大写字母有效,但 LimitTo 无效。有人帮忙吗?也许它在(流媒体,观众)有问题?

这里是 JSON:

{
    "Liquidixmike88": 1721,
    "DotaCinema": 746,
    "EternaLEnVyy": 649,
    "starladder1": 562,
    "Anuxinamoon": 165,
    "glhf_Reaves": 157,
    "Anzecha": 135
}
4

1 回答 1

1

因为limitTo过滤器仅适用于数组:

CTRL:

function($scope) {
  $scope.streamerItems = [
    {nick: "TopGun", viewers: 1822},
    {nick: "Liquidixmike88", viewers: 1721},
    {nick: "DotaCinema", viewers: 746},
    {nick: "DotaCinema1", viewers:732},
    {nick: "EternaLEnVyy", viewers: 649},
    {nick: "starladder1", viewers: 562},
    {nick: "Anuxinamoon", viewers: 165},
    {nick: "glhf_Reaves", viewers: 157},
    {nick: "Anzecha", viewers: 135}
  ];

}

看法:

<ul class="streamsList">
  <li class="streamsListItem" ng-repeat="streamer in streamerItems | limitTo:5">
    <h2>{{streamer.nick | uppercase}}</h2>
    <span>{{streamer.viewers}}</span>
  </li>
</ul>

演示 plunker

于 2013-03-02T08:14:03.380 回答