gpt4 book ai didi

ag-grid 无法读取属性 'setRowData',因为 gridOptions.api 未定义

转载 作者:行者123 更新时间:2023-12-04 22:18:59 35 4
gpt4 key购买 nike

我有一个在项目中工作的 ag-grid。但是现在当我将相同的内容移植到另一个页面时,我遇到了一些错误..我试图避免中间的 http 调用并直接尝试通过设置 ROW 数据

 $scope.gridOptions.api.setRowData(RowDatas);

但错误是“类型错误:无法读取未定义的属性‘setRowData’”

所以在调试时我意识到 api 是 Undefined 。这是我的完整代码。请检查我错过了什么..
<head>
<script src="js/angular_1_3_8.js"></script>
<script src="js/angular-filter.js"></script>
<script src="workbench/agGrid/dist/ag-grid.js?ignore=notused34"></script>
<script>
agGrid.initialiseAgGridWithAngular1(angular);
var app = angular.module("workbenchApp", ['angular.filter',"agGrid"]);
app.controller("workBenchCtrl", function ($scope, $http, $filter) {

var columnDefs = [
{headerName: "Name", field: "Name"},
{headerName: "Cr", field: "dc"},
{headerName: "Ac", field: "da"},
{headerName: "Mo", field: "dm"},

];

var RowDatas=[{"Name": "SUHDLOG.DAT", "dc": "1970-01-01 05:30:00", "da": "2002-12-27 00:00:00", "dm": "2002-12-27 09:51:22"},
{ "Name": "BOOTLOG.PRV", "dc": "1970-01-01 05:30:00", "da": "2005-04-01 00:00:00", "dm": "2005-04-01 15:13:30"},
{ "Name": "FRUNLOG.TXT", "dc": "1970-01-01 05:30:00", "da": "2002-12-27 00:00:00", "dm": "2002-12-27 09:52:56"},
{ "Name": "COMMAND.COM", "dc": "1970-01-01 05:30:00", "da": "2002-12-27 00:00:00", "dm": "1999-04-23 22:22:00"},
{ "Name": "BOOTLOG.TXT", "dc": "1970-01-01 05:30:00", "da": "2005-04-02 00:00:00", "dm": "2005-04-02 14:38:00"},
{ "Name": "DETLOG.TXT", "dc": "1970-01-01 05:30:00", "da": "2002-12-28 00:00:00", "dm": "2002-12-28 09:56:02"},
{ "Name": "CONFIG.SYS", "dc": "1970-01-01 05:30:00", "da": "2005-06-16 00:00:00", "dm": "2003-07-03 18:39:50"},
{ "Name": "DBLSPACE.BIN", "dc": "1970-01-01 05:30:00", "da": "2002-12-27 00:00:00", "dm": "1999-04-23 22:22:00"},
{ "Name": "MSDOS.SYS", "dc": "1970-01-01 05:30:00", "da": "2003-07-03 00:00:00", "dm": "2002-12-27 10:01:58"},
{ "Name": "DRVSPACE.BIN", "dc": "1970-01-01 05:30:00", "da": "2002-12-27 00:00:00", "dm": "1999-04-23 22:22:00"},
{ "Name": "MSDOS.---", "dc": "1970-01-01 05:30:00", "da": "2002-12-27 00:00:00", "dm": "2002-12-27 09:46:28"},
{ "Name": "SETUPLOG.TXT", "dc": "1970-01-01 05:30:00", "da": "2002-12-27 00:00:00", "dm": "2002-12-27 10:04:12"},
{ "Name": "WSOCK32.DLL", "dc": "1970-01-01 05:30:00", "da": "2005-06-16 00:00:00", "dm": "2002-12-27 09:47:10"},
{ "Name": "CFGWIZ.DLL", "dc": "1970-01-01 05:30:00", "da": "2005-02-26 00:00:00", "dm": "2002-12-27 09:47:12"},
];

$scope.gridOptions = {
angularCompileHeaders: true,
columnDefs: columnDefs,
rowData:[{"Name": "SUHDLOG.DAT", "dc": "1970-01-01 05:30:00", "da": "2002-12-27 00:00:00", "dm": "2002-12-27 09:51:22"}]
};

/*
$http.get('FileList.json').success(function (response) {
$scope.TData = response;
DateArray=$scope.TData.Files;
$scope.gridOptions.api.setRowData(DateArray);


});
*/
$scope.gridOptions.api.setRowData(RowDatas);

});
</script>
</head>
<body>
<div ng-app="workbenchApp">
<div ng-controller="workBenchCtrl">
<div ag-grid="gridOptions" class="ag-blue" style="height: 500px;"></div>
</div>
</div>
</body>

最佳答案

有同样的问题,似乎是由方法被调用两次引起的。第一次在api被定义之前,使得内部代码会崩溃。在第二遍时,定义了 api。

OnGridReady 对我不起作用,使用 vue 的 nextTick 或 timeout 也不起作用。

最终通过使用 if 解决了它:

if (this.gridOptions.api) {
this.gridOptions.api.setFilterModel(null);
}

这允许它第一次通过它而不会崩溃,然后第二次捕获它并完成工作。

(希望这对某人有所帮助。让我很沮丧。)

关于ag-grid 无法读取属性 'setRowData',因为 gridOptions.api 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42923160/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com