来自具有对象的对象的AngularJS ng-options
发布时间:2020-12-17 17:38:47 所属栏目:安全 来源:网络整理
导读:我试图将我的数据显示在列表中,如下所示: option value="4351"Atlanta/option 这是我的目标. $scope.cityList = { 4351:{name:"Atlanta",short="atlanta"},7355:{name:"Baltimore",short="baltimore"},1212:{name:"Chicago",short="chicago"},4398:{name:"D
我试图将我的数据显示在列表中,如下所示:
<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> 所以我的问题是: 解决方法
在cityList中使用name.name作为(city,name) – 在这种情况下,name.name是指您引入的新对象的name属性,它本身很可能名为name.
The documentation有点神秘,但你也可以在cityList中将它重命名为value.name for(key,value). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |