我正在迭代一个范围并为每个索引填充新的选择选项。这些选项与我正在迭代的范围无关,而是不同类型的选项。代码如下:
<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-model(就像 ng-init 中的那样)?例如,对于两个房间,ng-model 的结果应该类似于:
booking.roomSelection = [{id: 1, roomSelection: 'Double'}, {id: 2, roomSelection: 'Double'}]