我有這樣的代碼:過濾ngOptions通過屬性的屬性
//sample of data.
var combobox = new[] {
new { Key = 1, Value = "a[del]", isDelegate = true },
new { Key = 2, Value = "b[del]", isDelegate = true },
new { Key = 3, Value = "c", isDelegate = false },
new { Key = 4, Value = "d", isDelegate = false },
new { Key = 5, Value = "e[del]", isDelegate = true }
};
<select ng-model="selectedFilter" id="selectedFilter"
ng-options="item.Key as item.Value for item in ComboBox
track by item.Key" ng-change="loadData()">
<option>--</option>
</select>
我想添加一個ng-if
期權像這樣的結果:
<select ng-model="selectedFilter" id="selectedFilter"
ng-options="item.Key as item.Value for item in ComboBox track by item.Key" ng-change="loadData()">
<option value="item.Key" ng-if="item.isDelegate">{{item.Value}}</option>
</select>
這只是一個樣本。數據來自C# – AFetter 2014-10-31 04:51:36
不幸的是,我不知道給ng-options一個模板的方法。 – Sacho 2014-10-31 04:52:50
添加'|過濾器:{isDelegate:true}'在ng-options結尾,像這樣:ng-options =「item.Key as item.Value for item in ComboBox track by item.Key | filter:{isDelegate:true}」' – aarosil 2014-10-31 04:53:27