我的基本代碼到目前爲止另一個控制器:訪問Angular.js
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>
我新的角度(和一般的JS框架),和我不知道如何去了解這一點。我研究過像Ember這樣的其他框架,但沒有能夠以「簡單」的方式解決它。
這是一個用戶ID映射基本上與幾個小屋的id ...正確嗎? – mdance
@mdance正是:) – geniuscarrier