我正在努力将数据推送到我在我的角度应用程序中设置的ui-grid。
这是我做的:
<div ng-controller="MainCtrl">
<div id="grid1" ui-grid="gridOptions" class="grid"></div>
</div>
app.controller('MainCtrl', ['$scope', function ($scope) {
$scope.gridOptions.data = [
{
"firstName": "Cox",
"lastName": "Carney",
"company": "Enormo",
"employed": true
},
{
"firstName": "Lorraine",
"lastName": "Wise",
"company": "Comveyer",
"employed": false
},
{
"firstName": "Nancy",
"lastName": "Waters",
"company": "Fuelton",
"employed": false
}
];
}]);
但是我的网格中没有显示任何数据。谁知道为什么?
答案 0 :(得分:1)
问题出在你的gridOptions
对象中,你必须在分配数据之前定义它:
$scope.gridOptions = {data: []};
$scope.gridOptions.data = [
{
"firstName": "Cox",
"lastName": "Carney",
"company": "Enormo",
"employed": true
},
{
"firstName": "Lorraine",
"lastName": "Wise",
"company": "Comveyer",
"employed": false
},
{
"firstName": "Nancy",
"lastName": "Waters",
"company": "Fuelton",
"employed": false
}
];
问题是gridOptions没有定义,所以它在控制台中抛出了这个错误:TypeError: Cannot set property 'data' of undefined
。