[英]AngularJS - ngOptions expressions
I am trying to access a list of objects to use as ngOptions inside a Select element. 我试图访问一个对象列表,用作Select元素中的ngOptions。 No matter what I try, I cannot get the list to populate the Select. 无论我尝试什么,我都无法获得列表来填充Select。 If I render the options expression in the page, the data displays fine and seems to have the correct structure. 如果我在页面中呈现选项表达式,数据显示正常并且似乎具有正确的结构。 So I know its not a typo or something in my expression. 所以我知道这不是我的表达中的错字或其他内容。 I CAN access the data. 我可以访问数据。 Eg: 例如:
{{ form_event.providers.search_terms[form_event.type.toLowerCase()] }}
[{"group": "program", "name": "title"},
{"group": "program", "name": "aspect_ratio"},
{"group": "episode", "name": "aspect_ratio"},
{"group": "episode", "name": "house_id"}]
So, given the data structure, this is how I think it could be done in ng-options, but it doesn't work: 因此,考虑到数据结构,我认为这可以在ng-options中完成,但它不起作用:
<select ng-options="term.name group by term.group for term in
form_event.providers.search_terms[form_event.type.toLowerCase()]">
</select
Here is a fiddle: http://jsfiddle.net/9B3zN/1/ 这是一个小提琴: http : //jsfiddle.net/9B3zN/1/
Any clues would be great. 任何线索都会很棒。
Whenever you use ng-options
do not forget to add ng-model
attribute to select
otherwise it would not work 无论何时使用ng-options
都不要忘记添加ng-model
属性来select
否则它将无效
<select ng-model="selected" ng-options="term.name group by term.group for term in form_event.providers[form_event.type.toLowerCase()]">
<option value="">-- choose --</option>
</select>
Updated fiddle: http://jsfiddle.net/9B3zN/2/ 更新小提琴: http : //jsfiddle.net/9B3zN/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.