作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究 ui-grid 和 306_expandable_grid ,我使用了文档中的确切代码,但我遇到了错误问题。
应用程序.js
$http.get('resources/data/title2.json')
.success(function(data){
console.log(data);
console.log(data[0].Data);
console.log(data.length);
for(i = 0; i < data[i].length; i++){
data[i].subGridOptions = {
columnDefs: [
{name:"Title" },
{name:"Jan-10" },
{name:"Feb-10"},
{name:"Mar-10" },
{name:"Apr-10" },
{name:"May-10" },
{name:"Jun-10" },
{name:"Jul-10" },
{name:"Aug-10" },
{name:"Sep-10" },
{name:"Oct-10" },
{name:"Nov-10" },
{name:"Dec-10" }
],
data: data[i].Data
}
}
// $scope.subGridOptions.data = data;
$scope.gridOptions.data = data;
// $scope.title = data[0].Title;
});
<div ui-grid="row.entity.subGridOptions" style="height:150px;"></div>
TypeError: Cannot read property 'data' of undefined
at new <anonymous> (http://localhost/ng-Grid/resources/scripts/ui-grid-unstable.js:2883:41)
at Object.e [as invoke] (http://localhost/ng-Grid/resources/scripts/angular.min.js:36:456)
at E.instance (http://localhost/ng-Grid/resources/scripts/angular.min.js:75:118)
at http://localhost/ng-Grid/resources/scripts/angular.min.js:58:276
at r (http://localhost/ng-Grid/resources/scripts/angular.min.js:7:408)
at M (http://localhost/ng-Grid/resources/scripts/angular.min.js:58:260)
at http://localhost/ng-Grid/resources/scripts/angular.min.js:65:412
at http://localhost/ng-Grid/resources/scripts/angular.min.js:109:276
at h.$eval (http://localhost/ng-Grid/resources/scripts/angular.min.js:123:139)
at h.$digest (http://localhost/ng-Grid/resources/scripts/angular.min.js:120:220)
最佳答案
首先,确保您初始化 $scope.gridOptions
$http.get
之外success
打回来。只添加 $scope.gridOptions.data[i].subGridOptions
至 $scope.gridOptions
内success
打回来。 Reference :
You can't define the grid options in the success call. You need to define them on the scope in your controller and then set the data or column definitions, etc... from the success call.
if (typeof clientcode === 'string' && clientcode !== '') {
var payload = {
clientcode : storedClientcode
}
} else {
$location.path('/');
}
storedClientcode
是否存在由调用页面提供(通过共享应用根服务),如果没有,则重定向到应用程序主页。但是
ui-grid 显然对位于 上的页面进行了单独的子调用,并且这些子调用当然不会提供我在代码中寻找的数据,因此重定向发生在这些调用的幕后。没有产生任何错误(除了您所看到的),并且网格中没有显示任何数据。这花了我一些时间才弄明白(我对 AngularJS 还是很陌生,这是 ui-grid 对我来说的第一个应用程序)。希望这会对某人有所帮助,即使它没有解决这个问题。
关于angularjs - 306_expandable_grid - 无法读取 'data' 的属性未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26639233/
我是一名优秀的程序员,十分优秀!