我有一个简单的ng-grid
$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'}]
};
我在编辑屏幕中填充此网格,因此我必须检查来自REST API的复选框。但是我不能。这是代码。
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
}
});
有什么问题,为什么我无法更新我选择的项目数组并在ng-grid上正确显示?
答案 0 :(得分:0)
解决了这个问题。
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
}
});