Angular中的Ng-options过滤器

时间:2019-01-24 15:36:38

标签: angularjs filter ng-options angular-filters

我需要过滤一个下拉列表,以仅显示具有'isRequired = true'的选项。

当前,我可以将所有键和道具放入下拉菜单,但是过滤器无法正常工作。

错误消息:[filter notarray] 我不想将其更改为数组,相反我们可以更改过滤器吗?

<select ng-options="[key, prop] as key for (key, prop) in vm.createSchema.properties | filter:filterByRequired" ng-model="vm.selected"></select>

Angular.JS

$scope.filterByRequired = function () {  //this is in the vm's activate

            return function (item) {
                if (item.isRequired == 'false') {
                    return true;
                }
                return false;
            };




 vm.createSchema = { 
    "properties": {
                    "key": {
                        "type": "integer",
                        "isRequired": "true",

                    },
                "name": {
                  "type": "string",
                    "isRequired": "false",
                }
            };

0 个答案:

没有答案