类型错误:无法读取未定义的属性“核心”

问题描述 投票:0回答:1

我在尝试将数据绑定到数据网格选项时遇到问题。我读到刷新将有助于加载数据,但是当我添加逻辑时它会出错。

HTML代码:

<div ng-controller="MainCtrl">
    <br />
    <b>{{msg}}</b>
    <div id="grid1" ui-grid="gridOptions" class="grid" ui-grid-pagination></div>
</div>

JavaScript 代码:

   var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.edit', 'ui.grid.pagination']);
app.controller('MainCtrl', function($scope, $filter, $http, $timeout) {
    $scope.gridOptions = {
        enableSorting: true,
        enableRowSelection: true,
        enableRowHeaderSelection: false,
        enableFiltering: true,
        selectionRowHeaderWidth: 35,
        rowHeight: 35,
        multiSelect: true,
        enableGridMenu: true,
        columnDefs: [
                { name: 'client' },
                { name: 'qa_ver' },
                { name: 'qa_build_no' },
                { name: 'qa_build_date' },
                { name: 'prod_ver' },
                { name: 'prod_build_no' },
                { name: 'prod_build_date' },
                { name: 'prod_deploy_date' },
                { name: 'deploy_src' }      
    ],
        data: 'jsonData',
        paginationPageSizes: [5, 10, 25, 50],
        paginationPageSize: 5,
    }

    $timeout(function() {
        getJSONData();
        $scope.data = jsonData;
        $scope.gridOptions.data = $scope.data;
    }, 3000);
    
$scope.gridOptions = {
      onRegisterApi: function(gridApi){ $scope.gridApi = gridApi;}
    }
    $scope.gridApi.core.refresh();

抛出错误:

TypeError: Cannot read property 'core' of undefined

    at new <anonymous> (dashboard.html:114)
    at Object.invoke (angular.js:4625)
    at $controllerInit (angular.js:10027)
    at nodeLinkFn (angular.js:8965)
    at compositeLinkFn (angular.js:8333)
    at compositeLinkFn (angular.js:8336)
    at compositeLinkFn (angular.js:8336)
    at publicLinkFn (angular.js:8213)
    at angular.js:1715
    at Scope.$eval (angular.js:17025)
angularjs controller ui-grid
1个回答
2
投票

我认为正确的形式应该是:

 $scope.gridOptions = {
        enableSorting: true,
        enableRowSelection: true,
        enableRowHeaderSelection: false,
        enableFiltering: true,
        selectionRowHeaderWidth: 35,
        rowHeight: 35,
        multiSelect: true,
        enableGridMenu: true,
        columnDefs: [
                { name: 'client' },
                { name: 'qa_ver' },
                { name: 'qa_build_no' },
                { name: 'qa_build_date' },
                { name: 'prod_ver' },
                { name: 'prod_build_no' },
                { name: 'prod_build_date' },
                { name: 'prod_deploy_date' },
                { name: 'deploy_src' }      
        ],
        onRegisterApi: function(gridApi){ 
          $scope.gridApi = gridApi;
        }
        data: 'jsonData',
        paginationPageSizes: [5, 10, 25, 50],
        paginationPageSize: 5,
    }

    $timeout(function() {
        getJSONData();
        $scope.data = jsonData;
        $scope.gridOptions.data = $scope.data;
    }, 3000);


     $scope.gridApi.core.refresh();


..
..
.

}
© www.soinside.com 2019 - 2024. All rights reserved.