Html 选择选项数组
我使用ng repeat生成一些数据(用户名、登录名、角色和操作)。每个下拉列表(角色)都有相同的选项列表 预期产出: 每一行数据都可以有一个不同的选择选项(如图像),每当进行更改以保存更改时,都会进行服务调用 我的问题是,我不能为每一行选择不同的选项。因为它们都绑定到同一个ng模型,所以它们都检测到更改以及对新选项的所有更改Html 选择选项数组,html,angularjs,Html,Angularjs,我使用ng repeat生成一些数据(用户名、登录名、角色和操作)。每个下拉列表(角色)都有相同的选项列表 预期产出: 每一行数据都可以有一个不同的选择选项(如图像),每当进行更改以保存更改时,都会进行服务调用 我的问题是,我不能为每一行选择不同的选项。因为它们都绑定到同一个ng模型,所以它们都检测到更改以及对新选项的所有更改 <table> <thead> <tr> <th>Name</th> &l
<table>
<thead>
<tr>
<th>Name</th>
<th>Username</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="participant in model.participantData">
<td>{{participant.DisplayName}}</td>
<td>{{participant.UserLogin}}</td>
<td>
<label for="{{participant.ParticipantID}}" class="sr-only">
Choose a role
</label>
<select id="{{participant.ParticipantID}}" data-ng-options="role.RoleID as role.RoleName for role in model.rolesData" data-ng-change="roleChanged(participant)" data-ng-model="model.chosenRole">
</select>
</td>
<td>
<span aria-hidden="true" class="fa fa-minus-circle clickable"</span>
<span class="sr-only">Delete group member</span>
</td>
</tr>
</tbody>
</table>
名称
用户名
角色
行动
{{participant.DisplayName}
{{participant.UserLogin}
选择一个角色
不要给出相同的模型,而是通过ng repeat
实例为他们提供模型
像这样
data-ng-model="participant.chosenRole"
选择将是
<select
id="{{participant.ParticipantID}}"
data-ng-options="role.RoleID as role.RoleName for role in model.rolesData"
data-ng-change="roleChanged(participant)"
data-ng-model="participant.chosenRole">
</select>
您可以从model.participantData
中获取每一行的选定值,以便将属性添加到从服务调用填充的对象数组中。这是我第一次开始学习时应该学的东西,还是更多的时间?我甚至没有想到这一点。@Mathemats,这只是一些把戏。你无法从任何书籍或文档中学习到这样的东西。这些东西来自开发过程中的讨论。