gpt4 book ai didi

ag-grid-angular:错误类型错误:rowData.forEach 不是函数

转载 作者:行者123 更新时间:2023-12-03 23:21:32 25 4
gpt4 key购买 nike

试图在我的项目中加入 ag-grid-angular。我已经成功地让它通过过滤和排序处理静态数据。

我现在无法使用异步动态数据进行设置。

<ag-grid-angular 
style="width: 1100px; height: 1000px;"
class="ag-theme-balham"
[enableSorting]="true"
[enableFilter]="true"
id ="mygrid"
[animateRows]="true"
[rowData]="rowss | async"
[columnDefs]="columnDefs"
>
</ag-grid-angular>


在 component.ts 中:

public rowss: any = null;

this.rowss = this.Service.getReport(this.model)


我现在已经静态设置了列

columnDefs = [
{headerName: 'Make', field: 'make' },
{headerName: 'Model', field: 'model' },
{headerName: 'Price', field: 'price'}
];


在 Service.ts 中:

getReport( request: ReportModel ) {
return this.http.get( this.URL + super.jsonToQueryParam( request ) ).map(( response: Response ) => response.json() );
}


我收到此错误消息:

enter image description here

ng:///ProdCtnReportModule/ProdCtnReportComponent.ngfactory.js:100 ERROR TypeError: rowData.forEach is not a function
at ClientSideNodeManager.recursiveFunction (webpack-internal:///./node_modules/ag-grid/dist/lib/rowModels/clientSide/clientSideNodeManager.js:193)
at ClientSideNodeManager.setRowData (webpack-internal:///./node_modules/ag-grid/dist/lib/rowModels/clientSide/clientSideNodeManager.js:65)
at ClientSideRowModel.setRowData (webpack-internal:///./node_modules/ag-grid/dist/lib/rowModels/clientSide/clientSideRowModel.js:483)
at GridApi.setRowData (webpack-internal:///./node_modules/ag-grid/dist/lib/gridApi.js:156)
at Function.ComponentUtil.processOnChange (webpack-internal:///./node_modules/ag-grid/dist/lib/components/componentUtil.js:120)
at AgGridNg2.ngOnChanges (webpack-internal:///./node_modules/ag-grid-angular/dist/agGridNg2.js:363)
at checkAndUpdateDirectiveInline (webpack-internal:///./node_modules/@angular/core/esm5/core.js:12623)
at checkAndUpdateNodeInline (webpack-internal:///./node_modules/@angular/core/esm5/core.js:14151)
at checkAndUpdateNode (webpack-internal:///./node_modules/@angular/core/esm5/core.js:14094)
at debugCheckAndUpdateNode (webpack-internal:///./node_modules/@angular/core/esm5/core.js:14987)


我们从 API 调用中得到的数据与我静态设置时使用的数据相同。返回结果是请求的数组。
请建议需要做什么才能使其发挥作用。

最佳答案

这里的错误是您试图将 Observable 分配为 ag-grid 的数据。.map()返回一个 observable,您应该订阅它并向 ag-grid 提供数据。

像这样的东西——

const rowss$ = this.Service.getReport(this.model);
rowss$.subscribe(rowData => {
params.api.setRowData(rowData);
});

请记住,此错误 -

rowData.forEach is not a function



是一个很好的指标,表明您的 rowData 不是数组。

更多关于 map 与订阅 here

关于ag-grid-angular:错误类型错误:rowData.forEach 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53586265/

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