0
A
回答
0
- 陣列項目可以通過方形符號(訪問:
$Item = [{item1: 'lorem ipsum'}, {item2: [{inner_item:'lorem ipsum', inner_item2: 'lorem ipsum'}]},...]
我如何通過jQuery中指出像做到這一點在控制器例如:
item[0]
) - 對象參數可以通過訪問點符號(例如:
item1.paramater
)
var app = angular.module('app', []).controller('indexCtrl', function ($scope) {
$scope.item = [
{item1: 'lorem ipsum'},
{item2: [{inner_item:'lorem ipsum', inner_item2: 'lorem ipsum'}]
}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="indexCtrl">
<p>item[0]: {{item[0]}}</p>
<p>item[0].item1: {{item[0].item1}}</p>
<p>item[1]: {{item[1]}}</p>
<p>item[1].item2[0]: {{item[1].item2[0]}}</p>
<p>item[1].item2[0].inner_item: {{item[1].item2[0].inner_item}}</p>
</div>
1
你的數據是有點曖昧,但我會告訴你怎麼做兩種變化適當角度的方式:
var app = angular.module('myApp', []);
app.controller('TestCtrl', ['$scope', function($scope) {
$scope.items = [{country: 'Germany'},
{country: 'Spain'},
{country: 'England'}];
$scope.nestedItems = [{continent: 'Europe',
countries: [
{country: 'Germany'},
{country: 'Spain'},
{country: 'England'}]
}];
}]);
.single {
background-color: lightgreen;
}
.nested {
background-color: lightblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js">
</script>
<section ng-app="myApp" ng-controller="TestCtrl">
<div class="single">
<ul>
<li ng-repeat="item in items">
Country: {{item.country}}
</li>
</ul>
</div>
<div class="nested" ng-repeat="item in nestedItems">
<h2>Continent: {{item.continent}}</h2>
<ul>
<li ng-repeat="item in item.countries">
Country: {{item.country}}
</li>
</ul>
</div>
</section>
相關問題
- 1. 從django數組中獲取特定值
- 2. PHP從數組中獲取特定值
- 3. 從angular2 * ngFor數組獲取特定值
- 4. 如何從按鈕數組中獲取特定數組值
- 5. 如何從多維數組中獲取特定鍵/值對的特定數組
- 6. 如何使用JavaScript/Angular.js從數組中獲取單個值
- 7. 從數組中獲取數據庫中的特定值
- 8. LINQ從數組中獲取特定行
- 9. 從數組中獲取特定變量
- 10. 從數組中獲取特定項目
- 11. 從數組中輸出特定值並獲取正確的值
- 12. 從函數中獲取特定值
- 13. C#從特定組獲取值
- 14. 從數組中獲取特定的MySQL數據值?
- 15. PHP數組獲取特定值
- 16. 如何高效地從數組中獲取特定值?
- 17. 如何從json編碼數組中獲取特定值?
- 18. 從嵌套數組中獲取特定值
- 19. 從特定字符的數組中的字符串獲取值?
- 20. 如何從序列化數組中獲取特定值?有
- 21. 如何從CI中的會話數組獲取特定值?
- 22. 如何從數組中獲取特定值?
- 23. 從包含特定值的數組中獲取對象
- 24. 如何從XML文件中獲取特定的數組值?
- 25. PHP:從simplexml數組中獲取特定值
- 26. 從multidimentional數組獲取特定值鎖定爲ID
- 27. 從DataGrid獲取特定值
- 28. 從file_get_content獲取特定值
- 29. 從NSMutableArray獲取特定值
- 30. 從兩個下拉列表中獲取特定數組的特定值
作品對我感謝分配! –