0

所以...我正在尝试使用 ng-repeat 生成一个单选按钮组:

<div class="btn-group yb-radiobuttons">
    <button type="button" class="btn" ng-model="radioModel" btn-radio="'all'">All locations ({{dreamboxItemsByDate.length}})</button> 
    <button type="button" class="btn" data-ng-repeat="(key, value) in items" ng-model="radioModel" btn-radio="'{{key}}'">{{key}} ({{value.length}})</button>
</div>

这会生成以下 html:

<div class="btn-group yb-radiobuttons">
    <button class="btn ng-pristine ng-valid ng-binding" btn-radio="'all'" ng-model="radioModel" type="button">All locations (10)</button>
    <button class="btn ng-scope ng-valid ng-binding ng-dirty active" btn-radio="'Brooklyn, New York'" ng-model="radioModel" data-ng-repeat="(key, value) in items" type="button"> Brooklyn, New York (6) </button>
    <button class="btn ng-scope ng-valid ng-binding ng-dirty active" btn-radio="'London, UK'" ng-model="radioModel" data-ng-repeat="(key, value) in items" type="button"> London, UK (2) </button>
    <button class="btn ng-scope ng-pristine ng-valid ng-binding" btn-radio="'Tokyo, Japan'" ng-model="radioModel" data-ng-repeat="(key, value) in items" type="button"> Tokyo, Japan (2) </button>
</div>

第一眼看起来一切都很好,但是单击使用重复生成的任何按钮元素根本不会设置模型 - 只需单击所有位置的按钮即可设置模型。

plnkr:http ://plnkr.co/edit/J1LfRO?p=preview

任何想法为什么会发生这种情况/如何解决?

4

2 回答 2

0

使用这个片段怎么样:

<button type="button" class="btn" ng-repeat="(city, message) in items" ng-model="radio.model"     btn-radio="city">{{city}} ({{message}})</button>

jsFiddle 在这里工作:http: //jsfiddle.net/Stego/fvDcS/

于 2013-10-25T09:54:29.973 回答
0

尝试这个:

<button type="button" class="btn" data-ng-repeat="(key, value) in items" ng-model="radioModel" btn-radio="key">{{key}} ({{value.length}})</button>

注意btn-radio="key",只需放下{{}}''

于 2013-08-29T15:26:45.363 回答