Angularjs 未调用onRegisterApi函数,ui网格

Angularjs 未调用onRegisterApi函数,ui网格,angularjs,angular-ui-grid,Angularjs,Angular Ui Grid,我正在尝试使用ui网格显示表。该表显示良好,但未调用onRegisterApi函数。在我想使用vm.gridApi.core.refresh()方法之前,我甚至没有注意到它,因为表显示工作得很好。当我添加该方法时,它给了我vm.gridApi未定义的错误 我的控制器如下所示: function userEventData (resp) { $http({ method: "GET", url: resp.re

我正在尝试使用ui网格显示表。该表显示良好,但未调用onRegisterApi函数。在我想使用vm.gridApi.core.refresh()方法之前,我甚至没有注意到它,因为表显示工作得很好。当我添加该方法时,它给了我vm.gridApi未定义的错误

我的控制器如下所示:

function userEventData (resp) {
            $http({
                method: "GET",
                url: resp.results["@href"]
            }).success(function (responseData) {
                logger.info("userEventData responseData", responseData);
                vm.gridOptions.data = responseData;
                logger.info("gridOptions", vm.gridOptions.data);
                poulateGrid();
                //return responseData;
            });
        }

function populateGrid () {
            logger.info("populateGrid function activated");
            vm.dateFormat = "medium";
            var temp = vm.gridOptions.data;
            vm.gridOptions = {
                enableColumnMenu: true,
                enableFiltering: true,
                enableSelectAll: true,
                rowTemplate: gridService.getRowTemplate(),
                excludeProperties: ["meta"],
                onRegisterApi: function (gridApi) {
                    logger.info("onRegisterApi activated");
                    vm.gridApi = gridApi;
                    logger.info("vm.gridApi when defined", vm.gridApi);
                    vm.gridApi.grid.registerRowsProcessor(vm.singleFilter(), 200 );
                },
                columnDefs: [
                    {
                        field: "sun",
                        displayName: "Init User",
                        allowCellFocus: false,
                        enableGrouping: true,
                    },
                    {
                        field: "dun",
                        displayName: "Target User",
                        allowCellFocus: false,

                    },
                    {
                        field: "evt",
                        displayName: "Name",
                        allowCellFocus: false
                    },
                    {
                        field: "dip",
                        displayName: "What is affected",
                        allowCellFocus: false
                    },
                    {
                        field: "det",
                        displayName: "Time created",
                        allowCellFocus: false,
                        cellFilter: "date:grid.appScope.vm.dateFormat"
                    }
                ]

            }
vm.gridOptions = {}; // must have gridOptions defined first

function userEventData (resp) {
            $http({
                method: "GET",
                url: resp.results["@href"]
            }).success(function (responseData) {
                logger.info("userEventData responseData", responseData);
                logger.info("gridOptions", vm.gridOptions.data);
                populateGrid(); // call this first
                vm.gridOptions.data = responseData; // now you can load the data
                //return responseData;
            });
        }

function populateGrid () {
            logger.info("populateGrid function activated");
            vm.dateFormat = "medium";
            // var temp = vm.gridOptions.data; // this wont exist yet
            vm.gridOptions = {
                enableColumnMenu: true,
                enableFiltering: true,
                enableSelectAll: true,
                rowTemplate: gridService.getRowTemplate(),
                excludeProperties: ["meta"],
                onRegisterApi: function (gridApi) {
                    logger.info("onRegisterApi activated");
                    vm.gridApi = gridApi;
                    logger.info("vm.gridApi when defined", vm.gridApi);
                    vm.gridApi.grid.registerRowsProcessor(vm.singleFilter(), 200 );
                },
                columnDefs: [
                    {
                        field: "sun",
                        displayName: "Init User",
                        allowCellFocus: false,
                        enableGrouping: true,
                    },
                    {
                        field: "dun",
                        displayName: "Target User",
                        allowCellFocus: false,

                    },
                    {
                        field: "evt",
                        displayName: "Name",
                        allowCellFocus: false
                    },
                    {
                        field: "dip",
                        displayName: "What is affected",
                        allowCellFocus: false
                    },
                    {
                        field: "det",
                        displayName: "Time created",
                        allowCellFocus: false,
                        cellFilter: "date:grid.appScope.vm.dateFormat"
                    }
                ]
            }
            }
html


知道为什么会这样吗?谢谢

在使用HTTP请求中的数据初始化vm.gridOptions.data之后,您正在调用populateGrid()函数

尝试重新排序代码以执行以下操作:

function userEventData (resp) {
            $http({
                method: "GET",
                url: resp.results["@href"]
            }).success(function (responseData) {
                logger.info("userEventData responseData", responseData);
                vm.gridOptions.data = responseData;
                logger.info("gridOptions", vm.gridOptions.data);
                poulateGrid();
                //return responseData;
            });
        }

function populateGrid () {
            logger.info("populateGrid function activated");
            vm.dateFormat = "medium";
            var temp = vm.gridOptions.data;
            vm.gridOptions = {
                enableColumnMenu: true,
                enableFiltering: true,
                enableSelectAll: true,
                rowTemplate: gridService.getRowTemplate(),
                excludeProperties: ["meta"],
                onRegisterApi: function (gridApi) {
                    logger.info("onRegisterApi activated");
                    vm.gridApi = gridApi;
                    logger.info("vm.gridApi when defined", vm.gridApi);
                    vm.gridApi.grid.registerRowsProcessor(vm.singleFilter(), 200 );
                },
                columnDefs: [
                    {
                        field: "sun",
                        displayName: "Init User",
                        allowCellFocus: false,
                        enableGrouping: true,
                    },
                    {
                        field: "dun",
                        displayName: "Target User",
                        allowCellFocus: false,

                    },
                    {
                        field: "evt",
                        displayName: "Name",
                        allowCellFocus: false
                    },
                    {
                        field: "dip",
                        displayName: "What is affected",
                        allowCellFocus: false
                    },
                    {
                        field: "det",
                        displayName: "Time created",
                        allowCellFocus: false,
                        cellFilter: "date:grid.appScope.vm.dateFormat"
                    }
                ]

            }
vm.gridOptions = {}; // must have gridOptions defined first

function userEventData (resp) {
            $http({
                method: "GET",
                url: resp.results["@href"]
            }).success(function (responseData) {
                logger.info("userEventData responseData", responseData);
                logger.info("gridOptions", vm.gridOptions.data);
                populateGrid(); // call this first
                vm.gridOptions.data = responseData; // now you can load the data
                //return responseData;
            });
        }

function populateGrid () {
            logger.info("populateGrid function activated");
            vm.dateFormat = "medium";
            // var temp = vm.gridOptions.data; // this wont exist yet
            vm.gridOptions = {
                enableColumnMenu: true,
                enableFiltering: true,
                enableSelectAll: true,
                rowTemplate: gridService.getRowTemplate(),
                excludeProperties: ["meta"],
                onRegisterApi: function (gridApi) {
                    logger.info("onRegisterApi activated");
                    vm.gridApi = gridApi;
                    logger.info("vm.gridApi when defined", vm.gridApi);
                    vm.gridApi.grid.registerRowsProcessor(vm.singleFilter(), 200 );
                },
                columnDefs: [
                    {
                        field: "sun",
                        displayName: "Init User",
                        allowCellFocus: false,
                        enableGrouping: true,
                    },
                    {
                        field: "dun",
                        displayName: "Target User",
                        allowCellFocus: false,

                    },
                    {
                        field: "evt",
                        displayName: "Name",
                        allowCellFocus: false
                    },
                    {
                        field: "dip",
                        displayName: "What is affected",
                        allowCellFocus: false
                    },
                    {
                        field: "det",
                        displayName: "Time created",
                        allowCellFocus: false,
                        cellFilter: "date:grid.appScope.vm.dateFormat"
                    }
                ]
            }
            }

在使用HTTP请求中的数据初始化vm.gridOptions.data之后,将调用populateGrid()函数

尝试重新排序代码以执行以下操作:

function userEventData (resp) {
            $http({
                method: "GET",
                url: resp.results["@href"]
            }).success(function (responseData) {
                logger.info("userEventData responseData", responseData);
                vm.gridOptions.data = responseData;
                logger.info("gridOptions", vm.gridOptions.data);
                poulateGrid();
                //return responseData;
            });
        }

function populateGrid () {
            logger.info("populateGrid function activated");
            vm.dateFormat = "medium";
            var temp = vm.gridOptions.data;
            vm.gridOptions = {
                enableColumnMenu: true,
                enableFiltering: true,
                enableSelectAll: true,
                rowTemplate: gridService.getRowTemplate(),
                excludeProperties: ["meta"],
                onRegisterApi: function (gridApi) {
                    logger.info("onRegisterApi activated");
                    vm.gridApi = gridApi;
                    logger.info("vm.gridApi when defined", vm.gridApi);
                    vm.gridApi.grid.registerRowsProcessor(vm.singleFilter(), 200 );
                },
                columnDefs: [
                    {
                        field: "sun",
                        displayName: "Init User",
                        allowCellFocus: false,
                        enableGrouping: true,
                    },
                    {
                        field: "dun",
                        displayName: "Target User",
                        allowCellFocus: false,

                    },
                    {
                        field: "evt",
                        displayName: "Name",
                        allowCellFocus: false
                    },
                    {
                        field: "dip",
                        displayName: "What is affected",
                        allowCellFocus: false
                    },
                    {
                        field: "det",
                        displayName: "Time created",
                        allowCellFocus: false,
                        cellFilter: "date:grid.appScope.vm.dateFormat"
                    }
                ]

            }
vm.gridOptions = {}; // must have gridOptions defined first

function userEventData (resp) {
            $http({
                method: "GET",
                url: resp.results["@href"]
            }).success(function (responseData) {
                logger.info("userEventData responseData", responseData);
                logger.info("gridOptions", vm.gridOptions.data);
                populateGrid(); // call this first
                vm.gridOptions.data = responseData; // now you can load the data
                //return responseData;
            });
        }

function populateGrid () {
            logger.info("populateGrid function activated");
            vm.dateFormat = "medium";
            // var temp = vm.gridOptions.data; // this wont exist yet
            vm.gridOptions = {
                enableColumnMenu: true,
                enableFiltering: true,
                enableSelectAll: true,
                rowTemplate: gridService.getRowTemplate(),
                excludeProperties: ["meta"],
                onRegisterApi: function (gridApi) {
                    logger.info("onRegisterApi activated");
                    vm.gridApi = gridApi;
                    logger.info("vm.gridApi when defined", vm.gridApi);
                    vm.gridApi.grid.registerRowsProcessor(vm.singleFilter(), 200 );
                },
                columnDefs: [
                    {
                        field: "sun",
                        displayName: "Init User",
                        allowCellFocus: false,
                        enableGrouping: true,
                    },
                    {
                        field: "dun",
                        displayName: "Target User",
                        allowCellFocus: false,

                    },
                    {
                        field: "evt",
                        displayName: "Name",
                        allowCellFocus: false
                    },
                    {
                        field: "dip",
                        displayName: "What is affected",
                        allowCellFocus: false
                    },
                    {
                        field: "det",
                        displayName: "Time created",
                        allowCellFocus: false,
                        cellFilter: "date:grid.appScope.vm.dateFormat"
                    }
                ]
            }
            }