gpt4 book ai didi

javascript - 按属性的属性过滤 ngOptions

转载 作者:行者123 更新时间:2023-12-03 11:32:49 25 4
gpt4 key购买 nike

我有这个代码:

//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>

最佳答案

您可以使用过滤器

var app = angular.module('my-app', [], function() {

})

app.controller('AppController', function($scope) {
$scope.condition = {
isDelegate: true
}

$scope.combobox = [{
Key: 1,
Value: "a[del]",
isDelegate: true
}, {
Key: 2,
Value: "b[del]",
isDelegate: true
}, {
Key: 3,
Value: "c",
isDelegate: false
}, {
Key: 4,
Value: "d",
isDelegate: false
}, {
Key: 5,
Value: "e[del]",
isDelegate: true
}];
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="my-app" ng-controller="AppController">
<select ng-model="selectedFilter" id="selectedFilter" ng-options="item.Key as item.Value for item in combobox | filter:condition track by item.Key" ng-change="loadData()">
<option value="item.Key" ng-if="item.isDelegate">{{item.Value}}</option>
</select>
</div>

关于javascript - 按属性的属性过滤 ngOptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26667693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com