我有多个ng-repeat复选框列表,我目前正在使用ng-checked和ng-click来执行复选框。当我的后端服务器获取一些数据并解析到marketing.offers
时,复选框没有更新,保持默认状态,这是全部空白状态。
HTML
<div ng-repeat="o in offer_options">
<label for="{{ o.name }}" class="css-input css-checkbox css-checkbox-primary">
<input id="{{ o.name }}" type="checkbox" name="{{ o.name }}" ng-value="o.id"
ng-checked="existsOffer(o, marketing.offers)"
ng-click="toggleOffer(o, marketing.offers)"/>
<span></span> {{ o.name }}
</label>
</div>
控制器
$scope.offer_options = [
{
id: 0,
name: "SMS"
},
{
id: 1,
name: "Email"
},
{
id: 2,
name: "Messenger/Whatsapp/Wechat etc"
}
];
$scope.toggleOffer = function (item, list) {
var idx = list.map(function(e) { return e.id; }).indexOf(item.id);
if (idx > -1) {
list.splice(idx, 1);
}else {
list.push({
id: item.id,
name: item.name
});
}
};
$scope.existsOffer = function (item, list) {
if(!isEmpty(list)){
return list.map(function(e) {
return e.id;
}).indexOf(item.id) > -1;
}
return;
};
从API加载日期
marketing.offers => [{id:id,name:name},{id:id2,name:name2}]
但是复选框没有更新