我在尝试将数据绑定到数据gridOptions时遇到问题。我读到刷新会有助于加载数据但是当我添加逻辑时它会出错。
请帮忙......
<<<<<< HTML代码>>>>>>
theano
<<<<<< JavaScript代码>>>>>>>>
<div ng-controller="MainCtrl">
<br />
<b>{{msg}}</b>
<div id="grid1" ui-grid="gridOptions" class="grid" ui-grid-pagination></div>
</div>
&LT;&LT;&LT;&LT;&LT;&LT;错误抛出&gt;&gt;&gt;&gt;&gt;&gt;&gt;
TypeError:无法读取属性&#39;核心&#39;未定义的
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();
答案 0 :(得分: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();
..
..
.
}