所以我有一個字典數組。在字典中,它們具有以下特性:如何使用ng-repeat來索引動態生成的屬性列表?
的AttributeName 的AttributeValue 產品名稱
但對於每個字典,我有屬性名稱動態生成。這爲每個屬性附加索引(AttributeName0,AttributeName1等) 我這樣做的原因是因爲我使用的是ui-grid,並且它需要列名是唯一的,以便爲每個字典創建一個新列在
字典看起來是這樣的(在一個名爲resultsToSend數組): enter image description here
我試圖用NG-重複使用這些字典動態創建一個表單:
<div class="row" ng-repeat="result in resultsToSend">
<div class="col s2">
<md-input-container><label>{{result.AttributeName$index}}</label><input type="number" id="new-day-ARP-input" ng-model="result.AttributeName$index" /></md-input-container>
</div>
<div class="col s4">
<label>Select {{result.ProductName$index}} Material</label>
<md-select ng-model="result.ProductName$index}" md-on-close="clearSearchTerm()" data-md-container-class="selectdemoSelectHeader">
<md-select-header class="demo-select-header">
<input ng-model="searchTerm" type="search" placeholder="Search For Material..." class="demo-header-searchbox md-text">
</md-select-header>
<md-option ng-value="{{mat.ID}}" ng-repeat="mat in Materials | filter:searchTerm">{{mat.Name}}</md-option>
</md-select>
</div>
</div>
但我一直沒有成功找到我們如何(PropertyNameHere)$ index來訪問我試圖訪問的屬性。
有沒有人有任何建議?
如何添加新屬性?通過推或什麼? – Jenny
'var tempProductName =「ProductName」+ String(k); var tempAttributeName =「AttributeName」+ String(k); var tempAttributeValue =「AttributeValue」+ String(k); var tempArray = []; tempArray [tempProductName] =''; tempArray [tempAttributeName] = response.data [0] .Attributes [k] .Name; tempArray [tempAttributeValue] ='' $ scope.resultsToSend.push(tempArray);' – user44036
你不能訪問**結果**作爲一個對象,如:result。(PropertyNameHere)$ index,因爲結果是不可用的範圍有resultsToSend存在,並且結果用於通過resultToSend循環,因此使用它來訪問它:* * resultsToSend [$ index] .ProductName ** – Jenny