我有以下的html:遇到問題重複使用嵌套NG-重複和正確的項目NG-如果
<div ng-repeat="tab in tabs" ng-if="tabIsActive(tab, $index)">
<ul ng-repeat="section in tab.sections">
<h2 ng-class="productTitle" ng-repeat="child in section.children" ng-if="sideTabIsActive(section, $index)">
<img ng-src="{{ child.productImageURL }}"/>
<li>{{ child.title }}</li>
</ul>
</div>
這是 「標籤」 JavaScript對象是什麼樣子:
我想要的輸出是選擇該部分時爲每個部分列出的子類別標題(例如children0.title)和圖像(例如children0.productImageURL)。
實施例所需的輸出:
當分析天平被點擊
(ML image) //which is section0.child0.productImageURL
ML //which is section0.child0.title
(XS image) //which is section0.children1.productImageURL
XS //which is section0.child1ren.title
目前,我顯示該:
當分析天平點:
(ML image) //which is section0.children0.productImageURL
ML //which is section0.children0.title
(XPE image) //which is section1.children0.productImageURL
XPE //which is section1.children0.title
我怎樣才能列出每個部分的兩個孩子(和相關圖像)在哪一部分被選中(selectedSideIndex)?
除了上述HTML,這裏是相關的HTML和JavaScript,我在我試圖達到所需的輸出使用:
$scope.toggleSideSelect = function(ind){
$scope.selectedSideIndex = ind;
}
$scope.sideTabIsActive = function (tab, $index) {
var selectedIndexTest = $scope.selectedSideIndex
return $index==$scope.selectedSideIndex;
}
<div ng-repeat="tab in tabs" ng-if="tabIsActive(tab, $index)">
<ul ng-repeat="section in tab.sections" ng-click="toggleSideSelect($index)">
<li>{{ section.title }}</li>
<ul ng-repeat="child in section.children">
<li>{{ child.title }}</li>
</ul>
</ul>
</div>
JSON中全局對象的結構如何? – 2015-02-09 20:28:17
@RichardCotrina它是從app.data文件夾中的文件動態創建的,所以我沒有創建對象的JavaScript代碼片段向您展示。我可以寫出一個,因爲它很大,所以只需要一點。以下是來自鉻檢查員的相關對象的更好的鏡頭:http://i.imgur.com/rcdoY4X.png 這有幫助嗎? – user95227 2015-02-09 20:35:24
哦,那麼我建議你改變你的Dinamically生成的數據的結構,以適應你需要使用的東西和你需要展示的東西之間的平衡。 – 2015-02-09 21:04:07