我在使用点亮元素初始化网格实例时遇到困难,
这是我尝试过的示例,
import { Grid } from '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"}
];
specify the data this.rowData = [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];
let the grid know which columns and what data to use 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>
</div>
`; } }
您必须从代码中删除注释文本
**specify the data** this.rowData = [
**let the grid know which columns and what data to use** this.gridOptions
我还认为你忘记在这里删除逗号:
.gridOptions=${this.gridOptions}