无法读取未定义的属性“名称”

时间:2016-02-19 15:59:16

标签: angularjs angular-ui-grid

我的休息呼叫从数据库返回数据。我已经分别测试了其余的服务电话,发现一切都很好。当我尝试在前端显示它时,我收到此错误:

  

'TypeError:无法读取未定义的属性'name'

当我使用chrome调试时,我注意到了错误消息,但无法确定问题所在。

控制器

mdmApp.controller('draftReportTypeCalendarController', function($scope, $http, $location, $routeParams) {

        $scope.isSelected = false;
        $scope.buttonsDisabled = false;

        $scope.showSpinner = true;

        // TODO: routeParam reportTypeYear
        $http.get("/mdmservice/services/draftReportTypeCalendar")
            .success(function(data, status, headers, config) {
                $scope.draftReportTypeCalendars = data;
                if (data.errorMessage != null) {
                        $scope.error = true;
                        $scope.success = false;
                        $scope.errorMessage = data.errorMessage + ". [Error code : " + data.errorCode + "].";
                        $scope.buttonsDisabled = true;
                    } else {
                        $scope.error = false;
                        if($scope.draftReportTypeCalendars.length == 0){
                            $scope.warn = true;
                            $scope.warnMessage = "No records found."
                        }
                        //$scope.success = true;                        
                        //$scope.successMessage = "To be decided"
                        $scope.buttonsDisabled = false;
                    }
                }
            )
            .error(function(data, status, headers, config, statusText) {
                $scope.error = true;
                $scope.errorMessage = "A system error occured. Please contact EBA IT Helpdesk."
                $scope.buttonsDisabled = true;
            })
            .finally(function () {
                $scope.showSpinner = false;
            });


        $scope.gridOptions = {
                paginationPageSizes: [23, 50, 100, 200, 300, 400, 500, 1000],
                paginationPageSize: 23, 
        };

        $scope.gridOptions.data = 'draftReportTypeCalendars';
        $scope.gridOptions.enableFiltering = true;
        $scope.gridOptions.enableGridMenu = true;
        $scope.gridOptions.fastWatch = true;

        $scope.gridOptions.multiSelect = false;

        $scope.gridOptions.columnDefs = [ 
            {
                name : "referenceDate", width : "15%"
            },                          
            {
                name : "reportType", width : "10%"
            },
            {
                name : "entityName", width : "35%"
            }
        ];

        $scope.gridOptions.onRegisterApi = function(gridApi){
            // set gridApi on scope
            $scope.gridApi = gridApi;
            gridApi.selection.on.rowSelectionChanged($scope,function(row){
              $scope.selectedId = row.entity.entityId;
              $scope.isSelected = row.isSelected;
            });
          };   

浏览器日志

TypeError: Cannot read property 'name' of undefined
    at Grid.buildColumns (ui-grid.js:4436)
    at columnDefsWatchFunction (ui-grid.js:3176)
    at ui-grid.js:3162
    at Scope.$digest (angular.js:16664)
    at Scope.$apply (angular.js:16928)
    at done (angular.js:11266)
    at completeRequest (angular.js:11464)
    at XMLHttpRequest.requestLoaded (angular.js:11405)  

1 个答案:

答案 0 :(得分:0)

列定义中没有“名称”选项。 https://github.com/angular-ui/ui-grid/wiki/Defining-columns