我有一堆使用 ng-repeat 制作的 Angular-bootstrap 按钮:
<div class="btn-group">
<label class="btn btn-primary" ng-model="???what to insert???" btn-checkbox
ng-repeat="station in stationlist">{{station.name}}</label>
</div>
我想在 ng-model 中插入一些东西,这最终会给我一个关联数组,例如,buttons[key] = true|false。 key 必须是例如station.name,即派生自 ng-repeat 对象。
请注意,这些 Angular-bootstrap 按钮将 true|false 插入到连接的 ng-model 变量中;参见示例:http://angular-ui.github.io/bootstrap/#/buttons 。问题是我需要在模型中有一个数组元素,所以稍后我想迭代该数组。
最佳答案
也许你可以试试这个:
$scope.stationlist = [
{ name: 'a', checked: true },
{ name: 'b', checked: false },
{ name: 'c', checked: true },
...
];
并像这样绑定(bind)它:
<label class="btn btn-primary" ng-model="station.checked" btn-checkbox
ng-repeat="station in stationlist">{{station.name}}</label>
关于javascript - 由 ng-repeat : collect states under one array in the $scope model? 创建的按钮列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23980940/