作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我可以在 angularjs 中设置一个带有默认值的下拉列表,
<select name="repeatSelect" id="repeatSelect" ng-model="repeatSelect" ng-init=" repeatSelect = data[0].id">
<option ng-repeat="option in data" value="{{option.id}}">{{option.name}}</option>
</select>
如何使用 ng-options
实现同样的效果?我用,
<select name="repeatSelect"
id="repeatSelect"
ng-model="repeatSelect"
ng-init=" repeatSelect = option.id"
ng-options="option.name for option in data track by option.id">
</select>
但是没有用。 sample fiddle is here
最佳答案
使用 ng-init
为 ng-options
设置默认值。
这是:demo
<select name="repeatSelect"
id="repeatSelect"
ng-model="repeatSelect"
ng-init=" repeatSelect = data[0].id"
ng-options="option.id as option.name for option in data">
</select>
关于javascript - 如何在 ng-options 中设置默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33993468/
我是一名优秀的程序员,十分优秀!