Angularjs ng网格所选项目不';束缚
我有一个简单的ng网格Angularjs ng网格所选项目不';束缚,angularjs,ng-grid,Angularjs,Ng Grid,我有一个简单的ng网格 $scope.selectedSetups = []; $scope.gridSetups = { data: 'setups', selectedItems: $scope.selectedSetups, multiSelect: true, showFilter: true, showColumnMenu: false, showSelectionCheckbox: tru
$scope.selectedSetups = [];
$scope.gridSetups = {
data: 'setups',
selectedItems: $scope.selectedSetups,
multiSelect: true,
showFilter: true,
showColumnMenu: false,
showSelectionCheckbox: true,
columnDefs: [
{field:'_id', displayName:' ', width: 0},
{field:'name', displayName:'Name'},
{field:'type', displayName:'Type'}]
};
我在编辑屏幕中填充这个网格,所以我必须选中来自RESTAPI的复选框。但我不能。这是代码
SetupService.getSetups(function(data, result) {
if (result == 200) {
$scope.setups = data;
//$scope.selectedSetups.push(data[1]); // *If I do that, that works but manupilation of selectedSetups at the bottom doesn't work*
if($routeParams.id != null) {
RuleService.getRule($routeParams.id, function(rule, status) {
if(status == 200){
$scope.rule = rule;
angular.forEach(rule.commandIdList, function(item, key) {
angular.forEach($scope.setups, function(setup, key) {
if(setup.id == item){
$scope.selectedSetups.push(setup);
}
});
});
}else{
}
});
}
} else {
//TODO: Alert
}
});
出了什么问题,为什么我不能更新我的selected items数组并在ng grid上正确显示?这样解决了
SetupService.getSetups(function(data, result) {
if (result == 200) {
$scope.setups = data;
if($routeParams.id != null) {
RuleService.getRule($routeParams.id, function(rule, status) {
if(status == 200){
$scope.rule = rule;
setTimeout(function () {
angular.forEach(rule.commandIdList, function(item, key) {
angular.forEach($scope.setups, function(setup, key) {
if(setup.id == item){
$scope.gridSetups.selectRow(key, true);
$scope.$apply();
}
});
});
},10);
}else{
}
});
}
//calculateTypes(data);
} else {
//TODO: Alert
}
});
尝试包装
$scope.selectedSetups.push(设置)
和$apply
@MaximShoustin我试过了,但没有成功$scope.$apply(函数(){$scope.selectedSetups.push(setup);});仅为了测试,您是否尝试移动此行$scope.selectedSetups.push(数据[1])代码>在3个if语句中的每个语句中。只是为了验证它是否被执行。@klode是的,这也不起作用。这可能是一个愚蠢的评论,但是,你确定ifs条件是真的
。如果要执行(setup.id==item){}
中的console.log()?