[英]angular js array of objects for select with ngOptions
I have a character which can contain multiple skills. 我的角色可以包含多种技能。 Skills are available from an injected service. 可以从注入服务获得技能。 What I basically want is this: 我基本上想要的是:
<div ng-repeat="skill in character.getSkills()">
<select ng-model="skill" ng-options="select as s.toString() for s in getAllSkills()"></select>
<button ng-click="character.removeSkill(skill)" >Remove Skill</button>
</div>
With this code, the select box doesn't work as I would expect it. 使用此代码,选择框将无法正常运行。 Skills are not set in the character, and selections are not kept in the drop down. 角色中未设置技能,下拉菜单中未保留选择。
Am I missing something? 我想念什么吗?
Thanks in advance, roemer 在此先感谢,roemer
毕竟,我是通过子范围中的$ index属性引用character.skills数组中的技能:
<select ng-model="character.skills[$index]" ng-options="sk as sk.toString() for sk in getAllSkills()"></select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.