我需要我的所有下拉菜单选项有一个标签,以匹配他们的显示值。目前,我用来创建选项的代码是ng-options="country.Code as country.Country for country in countries"
。我知道做这件事的首选方法是使用track by
,但是因为我已经在使用as
了,所以当我这样做时,我的代码就会崩溃。我该如何解决这个问题呢?
发布于 2018-06-07 04:00:07
在使用as
时,您可以在NgOption中使用track by
,但是将完整的国家/地区对象(而不是country.Code)设置为NgModel很重要,否则track by语句将失败。
像这样试一下
ng-options="country as country.Country for country in countries track by country.Code"
https://stackoverflow.com/questions/50728501
复制相似问题