AngularJS链接选择

时间:2014-01-16 05:17:13

标签: angularjs select chaining

我正在尝试实现链式选择,但链条无法正常工作。

http://plnkr.co/edit/ndm7PFGK8akdaHra7Fdm?p=preview

我想要什么,需要:例如当选择'alpargatas'作为类别,并选择任何列出的品牌时,该类别仍应选择为'alpargatas'或选择'Calvin Klein'作为品牌,并且选择任何列出的类别时,品牌仍应选择为' Calvin Klein'。

任何解决方案,提示或建议?!事先提前

1 个答案:

答案 0 :(得分:1)

您需要按正确的顺序使用filter

category下拉列表

  1. 按照brand
  2. filter:{brand: filterObject.brand}: true//pass true for strict mode添加过滤条件
  3. 然后是unique过滤器,例如unique: 'category'
  4. 并上传orderBy过滤器,如orderBy:'category'
  5. HTML中,它看起来像是

    <select ng-model="filterObject.category" 
            ng-options="c.category as c.category for c in shoes|filter:{brand: filterObject.brand}: true| unique: 'category'| orderBy:'category'">
    <option value="" ng-value="undefined">-- Category:</option>
    

    类似于Brand下拉列表

    <select ng-model="filterObject.brand" 
            ng-options="b.brand as b.brand for b in shoes|filter:{category: filterObject.category}: true| unique: 'brand'| orderBy:'brand'">
    <option value="" ng-value="undefined">-- Brand:</option>
    

    看看dropdowns与主数据源$scope.shoes绑定,因此您不需要控制器中的其他过滤器。

    检查更新后的plunk

    注意正如@ m59所提到的,当您在寻找答案时,不应该删除您的帖子。