到目前为止我的基本代码:
function UsersCtrl($scope) {
$scope.users = [
{
"id": 1,
"usersName": "Matt Dance",
"favorites": {
"id":1,
"lodge_id":1
}
},
{
"id":2,
"usersName": "Jennifer Dance",
"favorites": {
"id":1,
"lodge_id":2
}
}
];
};
function LodgesCtrl($scope) {
$scope.lodges = [
{
id: 1,
lodgesName: 'Matt\'s Awesome Lodge',
lodgeOwnersName: 'Matthew D',
lodgeStreetAddress: '5555 J lane',
lodgeCity: 'Salt Lake city',
lodgeZip: '11111',
lodgeState: 'Utah'
},
{
id: 2,
lodgesName: 'Some Historic Lodge',
lodgeOwnersName: 'Santa Claus',
lodgeStreetAddress: '1 Clearwater Road',
lodgeCity: 'Grand Marais',
lodgeZip: '55555',
lodgeState: 'Minnesota'
},
{
id: 3,
lodgesName: 'Yellowstone Lodge',
lodgeOwnersName: 'The Feds',
lodgeStreetAddress: '1 Yellowstone Way',
lodgeCity: 'Yellowstone',
lodgeZip: '55555',
lodgeState: 'Wyoming'
},
{
id: 4,
lodgesName: 'Cool Lodge',
lodgeOwnersName: 'Awesome Guy',
lodgeStreetAddress: '1 awesome Road',
lodgeCity: 'Eagle Mountain',
lodgeZip: '55555',
lodgeState: 'Utah'
},
{
id: 5,
lodgesName: 'The last lodge',
lodgeOwnersName: 'Adam V',
lodgeStreetAddress: '444 Last Road',
lodgeCity: 'San Francisco',
lodgeZip: '55555',
lodgeState: 'California'
}
];
};
我希望用户能够看到他们喜欢的旅馆的旅馆名称。例如,用户收藏了 id 为 1 的旅馆。那么我如何遍历每个用户,并显示收藏的旅馆的标题?基本上,我需要lodge_id
在他们的收藏夹中为每个用户使用来显示旅馆名称。
到目前为止,我的 html 是:
<div ng-controller="UsersCtrl">
<ul class="unstyled">
<li ng-repeat="user in users">
{{user.usersName}}<br>
</li>
</ul>
</div>
我是 Angular(以及一般的 JS 框架)的新手,不知道该怎么做。我研究过其他框架,如 Ember,但无法以“简单”的方式解决它。