0

在第一级行,我可以$scope通过grid.appScope. 但在第二级行中,我知道grid.appScope返回的是什么。

我在二级行的列中有一个复选框,当用户点击时,我需要调用一个方法。在第一级行,我可以像下面这样

$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;
    });
}
4

1 回答 1

1

嵌套行有自己的范围,它们的父级是父行的范围。在您的示例中,只需写下即可ng-click="grid.appScope.scope.update_field

于 2017-03-14T19:50:51.523 回答