AngularJs有条件显示屏NG选项 [英] AngularJs conditional display for ng-options

查看:95
本文介绍了AngularJs有条件显示屏NG选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找了几个小时,我似乎无法在别处找到我的问题的答案。我记得我以前能够实现它,但由于某种原因,我失去了code和我似乎无法记得我做过什么,使其工作。

I've been searching for a few hours now and I can't seem to find the answer for my problem anywhere. I remember that I was able to implement it before but for some reason I lost the code and I can't seem to remember what I did to make it work.

我在一个选择框的数组使用NG选项试图显示数据。那我有没有问题。我需要实现的是,只有特定的阵列值将显示/纳入选择框。

I'm trying display data from an array in a select box using ng-options. That one I have no problems with. What I need to implement is that only certain array values will be displayed/included in the select box.

我的数据如下:

$scope.chartList = [ { "id" : 1, "name" : "chart 1", "order" : 1, "active" : false },
                     { "id" : 2, "name" : "chart 2", "order" : 2, "active" : true },
                     { "id" : 3, "name" : "chart 3", "order" : 3, "active" : true },
                     { "id" : 4, "name" : "chart 4", "order" : 4, "active" : true }, 
                     { "id" : 5, "name" : "chart 5", "order" : 5, "active" : true } ];

和我的HTML如下:

<select ng-model="toAddChart" ng-options="chart.id as chart.name for chart in chartList | filter:chart.active=='false'">
  <option value=""></option>
</select>

所以,我希望发生的是,如果属性活动的值为false那么它的阵列项目将显示唯一的一次/包含在选择列表中。我已经试过了筛选器属性的不同排列,但没有似乎工作。

So what I want to happen is that if the value of the attribute "active" is false then it's the only time the array item will be displayed/included in the select list. I've tried different permutations of the filter attribute but none seem to work.

我知道我可以很容易地在标签和使用NG-显示使用NG-重复,但我记得读书的地方(再次,我找不到在哪里),它不是实现它的正确方法和使用NG选项是正确的方法。

I know I can easily use ng-repeat in the tag and use ng-show but I remember reading somewhere (again, I can't find where) that it's not the proper way to implement it and that using ng-options is the correct way.

我真的相信我能之前做到这一点,而无需创建自定义的javascript过滤,但对我的生活我不记得我是怎么做到的。我希望有人能

I'm really really sure I was able to do it before without creating a custom javascript filter, but for the life of me I can't remember how I did it. I'm hoping someone can

希望有人能帮助我解决这个,因为我的想法。

Hope someone can help me with this because I'm out of ideas.

更新:

大斯科特,我想我明白了。

Great scott, I think I've got it.

而不是:

filter:chart.active=='false'

它应该是:

filter:chart.active='false'

这是用于等号只是数量。的捂脸

感谢您的答复,大家好。

Thanks for the responses, everyone.

推荐答案

大斯科特,我想我明白了。

Great scott, I think I've got it.

而不是:

filter:chart.active=='false'

它应该是:

filter:chart.active='false'

这是用于等号只是数量。捂脸

It's just the number of equal signs used. facepalm

感谢您的答复,大家好。

Thanks for the responses, everyone.

这篇关于AngularJs有条件显示屏NG选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆