0

我似乎无法从 AngularJS 中的嵌套 ng-repeat 中获取我需要的值。

我从服务器发送了以下数据:

[{"Your Turn":[{"gameToken":"sSFK0OHhYa8M4F6Z5Z1uNFnawQNVkZXj1GZyTEeSv2h8gntr9UrEU5FQsR9r8YWMWvjA6tePINbOm2Fc5u8U659QaRK0dju0","friendId":"522eec17e4b088a0a939cfdb","friendName":"Michelle","status":"You are waiting for Michelle Miguelamimio Agoramarketomercado to accept your challenge"}]},{"Their Turn":[{"gameToken":"sSFK0OHhYa8M4F6Z5Z1uNFnawQNVkZXj1GZyTEeSv2h8gntr9UrEU5FQsR9r8YWMWvjA6tePINbOm2Fc5u8U659QaRK0dju0","friendId":"522eec17e4b088a0a939cfdb","friendName":"Michelle Miguelamimio Agoramarketomercado","status":"You are waiting for Michelle to accept your challenge"}]}]

以及以下 HTML 模板:

<div ng-repeat="turn in data">
    <p>{{turn}}</p>
    <ul class="list-bare list-inline tab-group">
        <li ng-repeat="(key, value) in turn" class="tab tab-active txt-upper {{key | lowercase}}">{{key}}</li>
    </ul>
    <ul class="list-bare list-users clearfix">
        <li class="clearfix" ng-repeat="game in turn">
            <div class="avatar-container">
                <img class="avatar" ng-src="{{baseUrl}}/shobo/user/avatar/{{game.friendId}}" alt="{{game.friendName}}" />
            </div>
            <div class="list-users-info">
                <h3 class="text-cap">{{game.friendName}}</h3>
                <p>{{game.status}}</p>
            </div>
            <div class="list-users-status txt-center" ng-click="acceptChallenge(game.gameToken,game.friendId)">
                <div><i class="icon-chevron-right"></i></div>
            </div>
        </li>
    </ul>
</div>

我没有看到第二个 ng-repeat 输出的任何“游戏”值,并且不确定我做错了什么?

4

2 回答 2

1
<li class="clearfix" ng-repeat="game in turn">

应该

<li class="clearfix" ng-repeat="game in value">
于 2013-09-24T06:38:58.827 回答
0

需要对 data 和 html 进行一些更改以使 require html

        $scope.data=[{
        "Title":"Your Turn",
"Turn": [{
    "gameToken":"sSFK0OHhYa8M4F6Z5Z1uNFnawQNVkZXj1GZyTEeSv2h8gntr9UrEU5FQsR9r8YWMWvjA6tePINbOm2Fc5u8U659QaRK0dju0",
    "friendId": "522eec17e4b088a0a939cfdb",
    "friendName": "Michelle",
    "status": "You are waiting for Michelle Miguelamimio Agoramarketomercado to accept your challenge"
}]
  }, {
 "Title":"Their Turn",
"Turn": [{
    "gameToken": "sSFK0OHhYa8M4F6Z5Z1uNFnawQNVkZXj1GZyTEeSv2h8gntr9UrEU5FQsR9r8YWMWvjA6tePINbOm2Fc5u8U659QaRK0dju0",
    "friendId": "522eec17e4b088a0a939cfdb",
    "friendName": "Michelle Miguelamimio Agoramarketomercado",
    "status": "You are waiting for Michelle to accept your challenge"
}]
            }];

HTML

    <div ng-repeat="turn in data">
     <ul class="list-bare list-users clearfix">
    <h1>{{turn.Title}}</h1>
    <li class="clearfix" ng-repeat="game in turn.Turn">
        <div class="avatar-container">
            <img class="avatar" ng-src="{{baseUrl}}/shobo/user/avatar/{{game.friendId}}"      alt="{{game.friendName}}" />
        </div>
        <div class="list-users-info">
            <h3 class="text-cap">{{game.friendName}}</h3>
            <p>{{game.status}}</p>
        </div>
        <div class="list-users-status txt-center" ng-click="acceptChallenge(game.gameToken,game.friendId)">
            <div><i class="icon-chevron-right"></i></div>
        </div>
    </li>
   </ul>


       </div>

请参考下面的小提琴

http://jsfiddle.net/U3pVM/1476/

于 2013-09-30T09:19:00.323 回答