首頁  >  問答  >  主體

能否在LitElements中使用ag-grid-community函式庫?

<p>是否可以在LitElements中使用ag-grid-community? 這是我嘗試過的,但是無法使用下面的程式碼初始化ag-grid實例。 </p> <p>控制台錯誤 - ag-grid-community.auto.esm.js:45056 Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'。 </p> <pre class="brush:php;toolbar:false;">import { Grid } 從 'ag-grid-community'; export class myComponent extends LitElement { static scopedElements = { 'ag-grid': Grid }; constructor() { super(); this.columnDefs = [ {headerName: "Make", field: "make"}, {headerName: "Model", field: "model"}, {headerName: "Price", field: "price"} ]; this.rowData = [ {make: "Toyota", model: "Celica", price: 35000}, {make: "Ford", model: "Mondeo", price: 32000}, {make: "Porsche", model: "Boxter", price: 72000} ]; this.gridOptions = { columnDefs: this.columnDefs, rowData: this.rowData, }; const eGridDiv = document.querySelector('#myGrid'); new Grid(eGridDiv, this.gridOptions); } render() { return html` <div> <ag-grid .gridOptions=${this.gridOptions} ></ag-grid> </div> `; } }</pre>
P粉553428780P粉553428780406 天前413

全部回覆(1)我來回復

  • P粉893457026

    P粉8934570262023-08-15 11:16:55

    你必須從程式碼中刪除註解文字

    **指定数据** this.rowData = [    
    
    **让网格知道要使用哪些列和数据** this.gridOptions

    另外,我認為你忘記在這裡刪除逗號:

    .gridOptions=${this.gridOptions}

    回覆
    0
  • 取消回覆