好的,所以我按照以下方式构建了一个选择输入:
<select
id='change-connect-week-in-manage-panel-dropdown'
ng-change='changeConnectEditing()' class="form-control"
ng-model="connectData.connectId"
ng-options="opt.id as opt.name for opt in connectData.connects"
>
</select>
这构建了以下内容:
<select
id="change-connect-week-in-manage-panel-dropdown"
ng-change="changeConnectEditing()"
class="form-control ng-valid ng-dirty ng-valid-parse ng-touched"
ng-model="connectData.connectId"
ng-options="opt.id as opt.name for opt in connectData.connects"
>
<option value="0" selected="selected">Week 15</option>
<option value="1">Week 14</option>
<option value="2">Week 13</option>
<option value="3">Week 12</option>
<option value="4">Week 11</option>
</select>
我想创建它(现在注意每个选项标签上的id属性):
<select
id="change-connect-week-in-manage-panel-dropdown"
ng-change="changeConnectEditing()"
class="form-control ng-valid ng-dirty ng-valid-parse ng-touched"
ng-model="connectData.connectId"
ng-options="opt.id as opt.name for opt in connectData.connects"
>
<option id="1" value="0" selected="selected">Week 15</option>
<option id="2" value="1">Week 14</option>
<option id="3" value="2">Week 13</option>
<option id="4" value="3">Week 12</option>
<option id="5" value="4">Week 11</option>
</select>
我已经尝试了ng-options="opt.id as opt.name for opt in connectData.connects track by opt.id"
,但我无法弄清楚如何应用{{$index}}
通常可以使用的ID我不知道还能做些什么。感谢。
答案 0 :(得分:2)
使用ng-repeat
(https://docs.angularjs.org/api/ng/directive/ngRepeat)代替。 ng-options
不允许您向选项添加自定义属性。