【问题标题】:ng-options filter equal to ng-model from inputng-options 过滤器等于来自输入的 ng-model
【发布时间】:2016-01-21 08:37:09
【问题描述】:

我正在尝试将条件过滤器添加到我的ng-options。 The options should only be displayed when an id from the options array equals an id from a different select input.

第一个ng-options

<select ng-model="requestDepartment" ng-options="department.DepartmentID as department.DepartmentName for department in departments" class="form-control">
    <option value="">Select</option>
</select>

第二个ng-options带过滤:

<select ng-model="requestCategory" ng-options="category.CategorytName for category in categories | filter:{category.ParentID : requestDepartment}" class="form-control">
    <option value="">Select</option>
</select>

第二个ng-options 应该只显示与第一个ng-options 中的ng-model 匹配的条目。

数据结构如下:

DepartmentID: 1
DepartmentName: "IT"

ParentID: 1
CategoryName: "Sharepoint"

因此,如果选择部门“IT”,我只想显示与parentID 匹配的类别,在本例中为“Sharepoint”。

我试过 filter:{category.ParentID : requestDepartment} 没有运气。

有什么建议吗?

更新:

我添加了一个小提琴:http://jsfiddle.net/q53ro5sr/4/

【问题讨论】:

  • 在第一个选择上放一个 $watch 并在你的控制器中处理它。如果您要使用控制器设置小提琴,我也会向您展示我是如何做到的。
  • 请看我的更新。我添加了一个小提琴。

标签: javascript angularjs ng-options


【解决方案1】:

这应该可以工作

<select ng-model="requestCategory" 
        ng-options="category.CategoryName for category in categories | filter: { ParentID: requestDepartment }" 
        class="form-control">
      <option value="">Select</option>
</select>

这是Fiddle

【讨论】:

    猜你喜欢
    • 2016-11-28
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 2016-01-11
    相关资源
    最近更新 更多