2016-04-08 85 views
0

我有两个下拉字段,其中第二个依赖于第一个选择。角度下降与依赖关系的第一个下拉

第一次下拉式数据来自一个数据集。它列出了与帐户ng-repeat="option in acctList":1,4和7相关联的号码。 我想要转到其他数据集,找到匹配的帐户号码,然后显示与该帐户相关的客户。 (账户1有客户1-2,账户4有客户3-4,账户7有客户5-7)。当第一个选项没有被选中时,第二个下拉菜单应该不显示任何内容(空白)。

这是我plunker与两个下拉菜单:http://plnkr.co/edit/jDitkge1rx6GJzkdElJO?p=preview

这里是我的控制器:

angular.module("app", []) 
    .controller("MainCtrl", function($scope) { 
    $scope.test = "This is a test"; 
    $scope.defnum = 1; 
    $scope.acct_info = [ 
     { 
     "Req": "MUST", 
     "DefCom": "1" 
     }, 
     { 
     "Req": "NoMUST", 
     "DefCom": "5" 
     }, 
     { 
     "Req": "MUST", 
     "DefCom": "4" 
     }, 
     { 
     "Req": "MUST", 
     "DefCom": "7" 
     } 
    ]; 

    $scope.cust_info = [ 
     { 
     "Customer": "1", 
     "Com": "1" 
     }, 
     { 
     "Customer": "2", 
     "Com": "1" 
     }, 
     { 
     "Customer": "3", 
     "Com": "4" 
     }, 
     { 
     "Customer": "4", 
     "DefCom": "4" 
     }, 
     { 
     "Customer": "5", 
     "DefCom": "7" 
     }, 
     { 
     "Customer": "6", 
     "DefCom": "7" 
     }, 
     { 
     "Customer": "7", 
     "DefCom": "7" 
     } 
    ]; 
    }); 

我加ng-repeat="option in cust_info | filter:{ Com : filter.DefCom }"尝试筛选基于该第二SO回答:Filter ng-options from ng-options selection 但它不工作。 我试过使用ng-change,但我认为应该有一个更简单的方法,如filtertrack by。我想知道如果我应该从ng-repeat改为ng-option。任何人都可以通过简单的方式了解这一点?

回答

0

在你的第二个<option>标签使用ng-if,可能是,不管你想要

<select> 
    <option ng-selected="defnum == option.DefCom" ng-repeat="option in acct_info | filter:{Req:'MUST'}:true"> 
     {{ option.DefCom }} 
    </option> 

    </select> 
    <select> 
    <option ng-if="option.DefCom" ng-selected="" ng-repeat="option in cust_info"> 
     {{ option.Customer}} 
    </option> 

    </select> 
+0

这并不在本例中工作。当您在第一个下拉列表中选择“1”时,它应该只显示选项1和2.当您选择“2”时,它应该显示选项3和4等等。 – jenryb