使用 ui-grid,如何从嵌套行访问 $scope?
With ui-grid, how to access $scope from nested rows?
在第一级行上,我可以通过 grid.appScope
访问 $scope
。
但是在第二层,我知道什么是 grid.appScope
returns.
我在第二级行的列中有一个复选框,当用户点击时,我需要调用一个方法。在第一级行,我可以像下面那样做
$scope.update_field = function...
然后在 columndef
中添加 ng-click="grid.appScope.update_field
...
如何在第二级行上执行类似操作?
下面是代码,现在,checkfield
可以工作,但不能使 subcheckfield
工作。
controller('ctrlProductAssignment', function ($scope, $controller, $routeParams, api, libs, options, gui) {
$scope.update_field = function (rowEntity, colDef, newValue, oldValue) {
if (rowEntity.id > 0)
....
};
$scope.gridOptions = {
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
if (row.isExpanded) {
row.entity.subGridOptions = {
columnDefs: [
{ name: 'subcheckfield', displayName: 'Registered',
cellTemplate: '<input type="checkbox" ng-model="row.entity[col.name]" ng-click="grid.appScope.update_field(row.entity, { name:col.name }, row.entity[col.name], 0)">' },
]
};
api.raffle_productassignmentdetail.query({ raffle_id: $scope.deal.id, pa_id: row.entity.id }).$promise.then(function (response) {
row.entity.subGridOptions.data = response;
});
}
});
},
columnDefs: [
{ name: 'checkfield', displayName: 'Registered',
cellTemplate: '<input type="checkbox" ng-model="row.entity[col.name]" ng-click="grid.appScope.update_field(row.entity, { name:col.name }, row.entity[col.name], 0)">' },
]
};
api.raffle_productassignment.query({ raffle_id: $scope.deal.id, reseller_id: reseller_id }).$promise.then(function (response) {
$scope.gridOptions.data = response;
});
}
嵌套行有自己的作用域,父行是父行的作用域。在您的示例中,只需写下 ng-click="grid.appScope.scope.update_field
即可。
在第一级行上,我可以通过 grid.appScope
访问 $scope
。
但是在第二层,我知道什么是 grid.appScope
returns.
我在第二级行的列中有一个复选框,当用户点击时,我需要调用一个方法。在第一级行,我可以像下面那样做
$scope.update_field = function...
然后在 columndef
中添加 ng-click="grid.appScope.update_field
...
如何在第二级行上执行类似操作?
下面是代码,现在,checkfield
可以工作,但不能使 subcheckfield
工作。
controller('ctrlProductAssignment', function ($scope, $controller, $routeParams, api, libs, options, gui) {
$scope.update_field = function (rowEntity, colDef, newValue, oldValue) {
if (rowEntity.id > 0)
....
};
$scope.gridOptions = {
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
if (row.isExpanded) {
row.entity.subGridOptions = {
columnDefs: [
{ name: 'subcheckfield', displayName: 'Registered',
cellTemplate: '<input type="checkbox" ng-model="row.entity[col.name]" ng-click="grid.appScope.update_field(row.entity, { name:col.name }, row.entity[col.name], 0)">' },
]
};
api.raffle_productassignmentdetail.query({ raffle_id: $scope.deal.id, pa_id: row.entity.id }).$promise.then(function (response) {
row.entity.subGridOptions.data = response;
});
}
});
},
columnDefs: [
{ name: 'checkfield', displayName: 'Registered',
cellTemplate: '<input type="checkbox" ng-model="row.entity[col.name]" ng-click="grid.appScope.update_field(row.entity, { name:col.name }, row.entity[col.name], 0)">' },
]
};
api.raffle_productassignment.query({ raffle_id: $scope.deal.id, reseller_id: reseller_id }).$promise.then(function (response) {
$scope.gridOptions.data = response;
});
}
嵌套行有自己的作用域,父行是父行的作用域。在您的示例中,只需写下 ng-click="grid.appScope.scope.update_field
即可。