嵌套ng中的Angularjs单选按钮重复未选中
Angularjs Radio Buttons in Nested ng-repeat not checked
我有一个html模板,其中一个ng重复嵌套在父ng重复中。父项ng repeat包含单选按钮,用户可以在其中选择"满意"或"不满意",它们分别对应于值1和0。如果用户选择"不满意",则会显示一个详细的选项列表,以便他们可以选择更多的收音机以获取更多信息。这是html;
<div class="group" ng-repeat="group in Groups">
<table>
<tr>
<td>{{group.Description}}</td>
<td><input type="radio" value="1" name="{{group.Id}}" ng-model="group.SatisfactionLevel" /></td>
<td><input type="radio" value="0" name="{{group.Id}}" ng-model="group.SatisfactionLevel" /></td>
</tr>
</table>
<div class="group-detail" ng-class="{'hidden': group.SatisfactionLevel != 1}">
<table>
<tr ng-repeat="item in group.Details">
<td>{{item.Description}}</td>
<td><input type="radio" value="1" name="{{item.Id}}" ng-model="item.SatisfactionLevel" /></td>
<td><input type="radio" value="0" name="{{item.Id}}" ng-model="item.SatisfactionLevel" /></td>
</tr>
</table>
</div>
从服务器返回的json如下所示;
"Groups": [
{
"Id":"AA",
"Description":"Service",
"SatisfactionLevel":1,
"Details":[{"Id":"AA1","Description":"Cleanliness","SatisfactionLevel":1},
{"Id":"AA2","Description":"Timeliness","SatisfactionLevel":1}
]
},
{
"Id":"AB",
"Description":"Food",
"SatisfactionLevel":1,
"Details":[{"Id":"AB1","Description":"Price","SatisfactionLevel":1},
{"Id":"AB2","Description":"Portion","SatisfactionLevel":1}
]
}
]
除了嵌套ng repeat中的单选按钮未选中外,其他一切都正常。我可以在fiddler中看到满意级别属性包含值。有人看到我哪里错了吗?感谢
更新
代码确实没有什么问题。结果表明,Groups
中的不同项可以包含相同的Details
项。由于我使用name="{{item.Id}}"
作为name属性,所以其他组详细信息中具有相同名称但不同值的其他无线电会导致以前具有相同名称的无线电被取消选中。这是我的解决办法;
<td><input type="radio" value="1" name="{{group.Id}}-{{item.Id}}" ng-model="item.SatisfactionLevel" /></td>
因为组id是唯一的。
首先,您在两个input
中都有相同的值——我猜这是拼写错误?
其次,如果您使用value="1"
,它将被解释为字符串"1"
,但您的模型是整数1
。
相反,使用ng-value
:
<input type="radio" ng-value="0" name="{{item.Id}}" ng-model="item.SatisfactionLevel">
<input type="radio" ng-value="1" name="{{item.Id}}" ng-model="item.SatisfactionLevel">
相关文章:
- Ng点击记住单选按钮选择
- 将 ng 重复中的单选按钮设置为选中
- 嵌套ng中的Angularjs单选按钮重复未选中
- 如何在控制器内获取ng重复单选按钮值
- 使用嵌套ng中带有单选按钮的ng模型重复不起作用
- 角度ng内的多个单选按钮组重复
- ng单选按钮中的型号更改
- AngularJS-使用ng repeat构建的单选按钮的设置值
- 离子,棱角分明,每次更改时$state ng 中重置单选按钮组重复
- 如何在AngularJS(ng-repeat)中获取选定的单选按钮数据
- 在带有 ng 重复的动态单选按钮上设置值
- 单选按钮在嵌套的 ng 重复和过滤器中不起作用
- 使用ng重复,棱角分明的单选按钮
- NG-模型似乎只在模态视图内的离子单选按钮上绑定一种方式
- 单选按钮中的 ng 模型始终未定义
- UI 引导单选按钮在 ng-repeat
- AngularJS ng-repeat,两个单选按钮无法正常工作
- AngularJs 指令在更改时获取单选按钮 ng-model 值
- 单选按钮 ng-model 变为真/假(选中/未选中)
- 在Angularjs中将Select ng-options转换为单选按钮ng-repeat