0
我在我的控制器中有以下對象。AngularJs - 如何在ng-repeat中的每次迭代中通過嵌套數組對象進行篩選?
function MyCntrl($scope) {
$scope.colors = [
{name:'black', shade:'dark',variant:['metal','pure','knight']},
{name:'white', shade:'light',variant:['pure','knight']},
{name:'red', shade:'dark',variant:['metal','pure']},
{name:'blue', shade:'dark',variant:['metal','knight']},
{name:'yellow', shade:'light',variant:['chrome','silver','knight']}
];
}
有兩個問題。
1.如何在每個對象中創建一個不帶重複的'variant'數組的選擇框?這可能與ng選項?我在找這個 -
<select ng-model="selectedVariant">
<option>Metal</option>
<option>Pure</option>
<option>Knight</option>
<option>Chrome</option>
<option>Solver</option>
</select>
- 如何使用時,我可以將過濾器應用於每個變量數組NG-重複?我嘗試以下
<div ng-controller="MyCntrl">
<select ng-model="selectedVariant" ng-options="variant for variant in (c.variant for c in colors)"></select><br>
<ul>
<li ng-repeat="c in colors | filter:{c.variant:selectedVariant}">{{c.name}}</li>
</ul>
</div>
需要一個使用'selectedVariant'作爲謂詞的自定義過濾器 – charlietfl