我试图将我的数据显示在列表中,如下所示:
<option value="4351">Atlanta</option>
这是我的目标.
$scope.cityList = { 4351:{name:"Atlanta",short="atlanta"},7355:{name:"Baltimore",short="baltimore"},1212:{name:"Chicago",short="chicago"},4398:{name:"Dallas",short="dallas"} };
HTML
这只适用于键值对,但现在“值”是一个对象
<select class="select-city" ng-model="myCity" ng-options="name for (city,name) in cityList"></select>
所以我的问题是:
在这种情况下,如何填充ng-options?
解决方法
在cityList中使用name.name作为(city,name) – 在这种情况下,name.name是指您引入的新对象的name属性,它本身很可能名为name.
The documentation有点神秘,但你也可以在cityList中将它重命名为value.name for(key,value).