[英]AngularJS dynamic select inside ng-repeat
I'm printing a list of products in a table. 我正在表格中打印产品列表。 This list of products has a product type ( typeId
). 该产品列表具有产品类型( typeId
)。 I want to be able to change the typeId
of the product directly in the table by using a select input. 我希望能够通过使用选择输入直接在表中更改产品的typeId
。
The problem comes when I try to set the default option of the product in the select input, because It shoud be the option with the typeId
. 当我尝试在选择输入中设置产品的默认选项时,就会出现问题,因为它应该是typeId
的选项。
ng-repeat="x in screensList"
. ng-repeat="x in screensList"
。 The x represents a product. x代表乘积。
I tried using ng-init or ng-value, but it won't work. 我尝试使用ng-init或ng-value,但无法正常工作。 What value should be in the ng-model of each select? 每个选择的ng模型应包含什么值?
Code and images: 代码和图片:
<tbody>
<tr ng-repeat="x in screensList">
<th scope="row">
{{x.pantalla}}
</th>
<td>
{{x.description}}
</td>
<td>
<select class="form-control" ng-model="slideshowSelect" ng-options="y.title for y in slideshowsList track by y.id">
</select>
</td>
<td class="text-right">
<button type="button" ng-click="deleteService($event)" serviceId="{{x.id}}" class="btn btn-danger btn-sm">Eliminar</button>
</td>
</tr>
</tbody>
I think this is what you need: 我认为这是您需要的:
<select class="form-control" ng-model="x.idSlideshow" ng-options="y.id as y.title for y in slideshowsList">
</select>
Check the working example: fiddle link 检查工作示例: 小提琴链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.