我想使用ag-grid将传入数据显示为表格,并提供导出为CSV的选项。我使用here和here的引用将代码插入模板节点。
这是我的模板代码:
<script src="https://unpkg.com/ag-grid/dist/ag-grid.min.noStyle.js"></script>
<link rel="stylesheet" href="https://unpkg.com/ag-grid/dist/styles/ag-grid.css">
<link rel="stylesheet" href="https://unpkg.com/ag-grid/dist/styles/ag-theme-balham.css">
<div id="myGrid" style="height: 600px;width:500px;" class="ag-theme-balham"></div>
<script>
(funtion(scope) {
var columnDefs = [
{headerName: "Make", field: "make"},
{headerName: "Model", field: "model"},
{headerName: "Price", field: "price"}
];
//
var rowData = [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];
//
var gridOptions = {
columnDefs: columnDefs,
rowData: rowData
};
//
var eGridDiv = document.querySelector('#myGrid');
var testGrid = new agGrid.Grid(gridOptions);
//
scope.$watch('msg', function(msg) {
if (msg) {
row = [
{make: "Toyota", model: "Celica", price: 35000}
];
testGrid.setRowData(row);
}
}
)
}
)(scope);
</script>
但是,我一直收到这个错误:
Uncaught SyntaxError: Unexpected token {
at m (app.min.js:20)
at Re (app.min.js:20)
at w.fn.init.append (app.min.js:20)
at w.fn.init.<anonymous> (app.min.js:20)
at z (app.min.js:20)
at w.fn.init.html (app.min.js:20)
at app.min.js:565
at m.$digest (app.min.js:165)
at m.$apply (app.min.js:168)
at app.min.js:181
如何通过此错误并将MQTT有效负载显示为表?