Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 根据条件显示ng选项_Angularjs - Fatal编程技术网

Angularjs 根据条件显示ng选项

Angularjs 根据条件显示ng选项,angularjs,Angularjs,这是我的数据 This.dynamicCmb = [{ id: 1, label: 'aLabel', subItem: ['aSubItem1','aSubItem2','aSubItem3'] }, { id: 2, label: 'bLabel', subItem: [ 'bS

这是我的数据

This.dynamicCmb = [{
                id: 1,
                label: 'aLabel',
                subItem: ['aSubItem1','aSubItem2','aSubItem3']
            }, {
                id: 2,
                label: 'bLabel',
                subItem: [ 'bSubItem' ]
            }];
我想根据给定的值(即id或标签)显示“子项”数据。如果我搜索任何一个,它应该显示值

<input type="text" ng-model="vm.selectedColumn" /> //Textbox to take either id or name value
    <input type="button" value="Get" ng-click="GetCmbValue()" /> //On click of button it should load dropdown
    <select ng-options="item.name for item in vm.selectedColumn.subItem" ng-model="vm.selected"></select>

例如:如果我在文本框中给出“1”,则“1”的子项应显示出来。如果我在文本框中输入'alabel',则也应显示'alabel'的子项。它应该在id或标签上搜索我提供的任何内容。请帮助我执行此操作

您可以将筛选器附加到您的ngOption。这样,每次您在文本框中键入值时,它都会相应地过滤数据。 我们将textbox的输出绑定到过滤器

.js文件

 This.GetCmbValue = function () {
// I should load drop down value here
            };
    app.filter('itemFilter', function() {

    return function(input,val) {
        var out = new Array();
        angular.forEach(input, function(item) {
            if (item.id == val || item.label == val) {
                out = out.concat(item.subItem);
            }
        });
        return out;
    };
});
HTML文件

<input type="text" data-ng-model="val">
<select data-ng-options="item for item in dynamicCmb | itemFilter : val" data-ng-model="selected"></select>

通过以下方法更改您的选择代码

     <select ng-options="item.name for item in vm.selectedColumn.subItem|filter:{Id:vm.selectedColumn}"   ng-model="vm.selected"></select>