angular.js - 关于 angularjs 的 ng-options 指令
PHPz
PHPz 2017-05-15 16:59:55
0
3
620

我通过 ajax 在控制器中拉取到一个数组,var fruits = ['apple', 'banana'],希望实现的是如下效果:

<select>
  <option value='apple'>苹果</option>
  <option value='banana'>香蕉</option>
</select>
<select ng-options="fruit for fruit in fruits">
</select>

得到了

<select ng-options="fruit for fruit in fruits">
  <option value="0" selected="selected" label="apple">apple</option>
  <option value="1" selected="selected" label="apple">banana</option>
</select>

应该怎么通过修改 ng-options 标签来修改 value 的值呢?

PHPz
PHPz

学习是最好的投资!

全部回复(3)
伊谢尔伦

干脆直接ng-repeat option 吧···

其实也是有解决办法的:
http://stackoverflow.com/questions/12139152/how-to-set-the-value-property-in-angularjs-ng-options

大家讲道理

fruit改成对象数组的方式

伊谢尔伦

雷雷

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板