user1269586
user1269586

Reputation: 370

Access multidimensional dictionary in AngularJS

I'm working on a project in AngularJS.

I have JSON as

{
  "leagues":{
    "aLeague":{
      "country":"aCountry",
      "matchs":{
        "aUniqueID1":{
          "date":"2014-09-07 13:00:00",
          "guest_player":"Me",
          "host_player":"Tom",
          "odds":{
            "guest":"2.80",
            "host":"2.25",
            "null":"2.85"
          },
          "score":"0 - 0"
        },
        "aUniqueID2":{
          "date":"2014-09-07 18:30:00",
          "guest_player":"Bryan",
          "host_player":"Me",
          "odds":{
            "guest":"3.25",
            "host":"1.98",
            "null":"2.95"
          },
          "score":"0 - 0"
        }
      }
    }
  }
}

And I want to display it guest_playerand host_playerin a ng-repeat.

But I'm not able to access to aUniqueID1 or aUniqueID2.

Any ideas?

Upvotes: 0

Views: 1049

Answers (2)

Josep
Josep

Reputation: 13071

Like this?:

<li ng-repeat="(key, item) in data.leagues.aLeague.matchs">
<span>User ID: {{key}}</span>
<span>Guest Player: {{item.guest_player}}</span>
</li>

The first span will display the key of the item (the value that you were asking about), the second one the attribute guest_player of the item.

Upvotes: 1

sylwester
sylwester

Reputation: 16498

Please see here:http://jsbin.com/wekow/1/edit

<p ng-repeat="(key, item) in data.leagues.aLeague.matchs">
Guest Player :{{item.guest_player}}<br/>
Host Player :{{item.host_player}}
</p>

Upvotes: 2

Related Questions