我正在努力填充select表单元素。以下是我到目前为止所掌握的语法。它不会抓取program.title并填充ngOptions。
<select ng-model="student.program" ng-options="program.title for program in programList.title">
<option value="">Select A Program</option>
</select>下面是我在Firebase上数据的基本JSON结构:
{ "-JNIBeRDAuNN9c7SGZ91" : { "location" : "Online", "director" : "Shawn Clark", "title" : "Web Design & Development" }, "-JNIBuaQlWyEyWRjONPa" : { "location" : "Online", "director" : "Walen Morrow", "title" : "Graphic Design" }, "-JNIBmIwasMYOPRPupHl" : { "location" : "Campus", "director" : "Tracy Monohan", "title" : "Web Design & Development" }, "-JNKGPNj-lGzqHJ92RTD" : { "location" : "Online", "director" : "Glen Speedy", "title" : "Theory of Animation & Physics" }, "-JNK9oTO97PfSo-0wQfY" : { "location" : "Campus", "director" : "John Myers", "title" : "Instructional Design & Technology" }, "-JNIC3Tldo-Qi3ru2ph7" : { "location" : "Campus", "director" : "George Narrow", "title" : "Graphic Design" }, "-JNK8cdgdHKjH2meKl9x" : { "location" : "Online", "director" : "Stacy McNally", "title" : "Instructional Design & Technology" } }
发布于 2014-05-20 04:39:44
我相信你是在找
<select ng-model="student.program" ng-options="program.title for (id, program) in programList"><option value="">Select A Program</option></select>JSON的根对象是一个对象,而不是一个数组。关于对象数据源,请参阅角文档。
见柱塞
发布于 2014-05-20 04:22:23
试试下面的代码。
它应该能发挥作用:
<select ng-model="student.program" ng-options="program.title for program in programList"><option value="">Select A Program</option></select>谢谢
https://stackoverflow.com/questions/23750888
复制相似问题