亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在反應功能組件中添加 valueFormatter 時,Ag Grid 無法加載

在反應功能組件中添加 valueFormatter 時,Ag Grid 無法加載

胡子哥哥 2022-10-21 10:29:08
我在反應功能組件中使用 AgGrid 顯示一些數據。對于作為對象的值,我試圖顯示它們的 json 值,我在 colDefs 中使用了 valueFormatter 選項,如下面的代碼所示。但是當我使用這個時,我得到一個錯誤:Error: ag-Grid: cannot get grid to draw rows when it is in the middle of drawing rows. Your code probably called a grid API method while the grid was in the render stage. To overcome this, put the API call into a timeout, eg instead of api.refreshView(), call setTimeout(function(){api.refreshView(),0}). To see what part of your code that caused the refresh check this stacktrace.如果我不使用 valueFormatter 選項,則不會出現上述錯誤。我知道我需要根據錯誤在準備好網格時加載網格,但我不確定如何在反應功能組件中執行此操作。代碼示例:import React, { useState } from "react";import { AgGridReact, ICellRendererReactComp } from "ag-grid-react";function Test(props) {  const [rowData, setRowData] = useState(null);  const defaultColDef = {    sortable: true,    filter: true,    resizable: true,  };  const columnDefs = [    {      headerName: 'Sample Key',      field: 'sampleKey',      valueFormatter: (val) => JSON.stringify(val),    },    //OTHER COLDEFS  ]    return (    <div className="container-fluid">        <div className="card mt-2 p-3 bg-red shadow p-3 mb-5 bg-white rounded">          <div            className="ag-theme-balham"            style={{ height: "500px", width: "100%" }}          >            <AgGridReact              columnDefs={columnDefs}              rowData={rowData}            ></AgGridReact>          </div>        </div>    </div>  );}export { Test };
查看完整描述

1 回答

?
POPMUISE

TA貢獻1765條經驗 獲得超5個贊

你的問題是:JSON.stringify(val)

您正在嘗試在圓形結構中使用 stringify 。

http://img1.sycdn.imooc.com//635204150001d12310040198.jpg

因此,如果您將其更改為val.value它對您有用。

你可以在這里看到一個例子


查看完整回答
反對 回復 2022-10-21
  • 1 回答
  • 0 關注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號