我有这样的情况:
<span ng-repeat="personNum in unit.PricePerson">
{{personNum}}
<select ng-model="personNum"
ng-options="o as o for o in unit.PricePerson track by $index"></select>
</span>unit.Price是数字数组,类似于5、6、7、8、9,但每个选择的值为9。我想先选择选择的选项5,其他的一个6,等等,我注意到我不能用鼠标改变选项。
有5个复选框生成,这是很好的,也有数字从5到9生成的选项,在每个选择。这些都没问题。
发布于 2015-07-20 14:51:13
您的问题有点不清楚,但看起来您的ng选项配置有问题。
通常不建议使用select和track,因为它们不是一起设计的,而且可能会产生意想不到的结果。另外,您正在您的ng选项中使用unit.PricePerson引用,而不是单个迭代对象personNum。
你应该有这样的东西:
<span ng-repeat="personNum in unit.PricePerson">
{{personNum}}
<select ng-model="personNum.selectedOption"
ng-options="o as o for o in unit.PricePerson">
</select>
</span>但是,如果没有看到javascript对象PricePerson,我就无法确定您的ng选项配置应该是什么。请看一下AngularJS ngOptions API。在参数部分,有为ng-选项表达式提供的建议模板。
发布于 2015-07-20 14:37:07
您的问题的一部分可能是$index在您的选择.看看下面的柱塞。另外,使用ng-init设置默认值。
http://plnkr.co/edit/2ZN1J61PD1Ev2OK1tezg
守则:
<span ng-repeat="personNum in unit.PricePerson">
<select ng-init="select[$index]=personNum" ng-model="select[$index]" ng-options="o as o for o in unit.PricePerson">
</select>
</span>正如@cyan建议的那样,我认为您还需要ng-模型,而不是外部ng-重复中的变量。
希望这能有所帮助。
https://stackoverflow.com/questions/31518734
复制相似问题