Angular ng-options按问题跟踪 [英] Angular ng-options track by issue

查看:75
本文介绍了Angular ng-options按问题跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ng-options显示的对象数据集.我使用track by

I have a data set of objects that I'm displaying using ng-options. I'm binding the objects ID value to the value using track by

当前,包括数据值,但它们以逗号显示.例如...

Currently, the data values are being included but they're being displayed with commas. For example...

$scope.items = [
   {ID: '2012', Title: 'Chicago'},
   {ID: '2013', Title: 'New York'},
   {ID: '2014', Title: 'Washington'},
];

<select ng-options="item.Title for item in items track by item.ID">
</select>

但这将呈现...

<option value="2,0,1,2" label="Chicago">Chicago</option>
<option value="2,0,1,3" label="New York">New York</option>

为什么要添加这些逗号,如何删除它们?

Why are these commas being added, and how can I remove them?

推荐答案

您不需要跟踪依据:

<select ng-options="i.ID as i.Title for i in items" ng-model="someModel"></select>

渲染后,您将拥有:

<option value="2012">Chicago</option>
<option value="2013">New York</option>

这篇关于Angular ng-options按问题跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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