【问题标题】:AngularJS: Filter ng-options not having specific valuesAngularJS:过滤没有特定值的ng-options
【发布时间】:2013-12-09 23:06:18
【问题描述】:

我想过滤这样的选择:

<select ng-model="test" ng-options="c as c.label group by c.type for c in columns
| filter:{c.type:'!field'} | filter:{c.type:'!map'}"></select>

编辑:添加列模型:

Columns = [
{
    name: "name",
    label: "Label",
    info: "Information displayed in help",
    type: "type",
    view: "html template",
    style: "min-width: 10em;",
    show: true
},
{
 ...
}
];

列用于多种用途,为了优化我的代码,我需要它也在 Select 中,但没有类型为“字段”或“地图”的条目

然而,我可以从所有内容中进行选择,甚至包括“字段”和“地图”类型的条目。 有干净的方法吗?

【问题讨论】:

  • 请发布您的模型columns

标签: angularjs angularjs-filter


【解决方案1】:

AngularJS 不过滤

<select ng-model="test" ng-options="c as c.label group by c.type for c in columns
    | filter:{ type : '!field' }
    | filter:{ type : '!map' }">
</select>

Fiddle

来自docs

"...可以通过在字符串前面加上!."

来否定谓词

"模式对象可用于过滤数组包含的对象的特定属性。例如 {name:"M", phone:"1"} 谓词将返回一个包含属性名称的项目数组“M”和包含“1”的属性电话...”

【讨论】:

  • 感谢帮助。特别是关于按原样使用过滤器变量“type”的部分。而不是 c.type .
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多