【发布时间】:2017-02-06 00:01:05
【问题描述】:
我在使用 Icon collection-repeat with ion-radio 检查选定值时遇到问题。
使用collection-repeat,如果选中的项目是列表中的第一个项目,设置checked 将不起作用。我发现,为了让它工作,我需要延迟分配列表数据。
(如果使用ng-repeat,它可以工作。但是列表可能很长,所以我需要使用collection-repeat)
例子,
模板)
<ion-content class="has-header" ng-controller="Ctrl">
<div class="list">
<ion-radio
collection-repeat="item in list"
ng-model="selectedItem"
ng-value="item.id">
{{ item.n }}
</ion-radio>
</div>
</ion-content>
控制器)
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
})
.controller('Ctrl',function($scope, $timeout) {
$scope.selectedItem = 1; // the first item
var list = [];
for (index = 1; index < 3; ++index) {
list.push({id: index, n: 'Item n. ' + index});
}
$scope.list = list;
});
不会检查列表的第一项。为了让它发挥作用,
替换
$scope.list = 列表;
与
$timeout(function() {
$scope.list = list;
}, 500);
我想知道它为什么会发生,我不认为 500ms 是有保证的,所以我需要知道解决这个问题的正确方法。请给我建议。
【问题讨论】: