我遍历一个范围并为每个索引填充新的选择选项。选项与我正在迭代的范围无关,但是是不同类型的选项。代码如下:在选择中指定对象
<div ng-repeat="i in range(booking.numberOfRooms) track by $index">
<p>Room {{$index + 1}}</p>
<select ng-model="booking.roomSelection[$index]" ng-options="obj.roomType as obj.roomType for obj in roomTypes" ng-init="booking.roomSelection[$index] = { id: $index + 1, roomType: 'Double' }"> </select>
</div>
我如何分配一个对象数组到NG-模型(像在NG-INIT)?例如。对于两房,NG-模型的结果应该是这个样子:
booking.roomSelection = [{id: 1, roomSelection: 'Double'}, {id: 2, roomSelection: 'Double'}]
你也可以使用'ng-model =“booking.roomSelection [$ index]”'if'ng-options =“obj as obj.roomType for obj in roomTypes”'。 –