const myGridOptions = {
columnDefs: [
{ field: 'id', headerName: 'ID', minWidth: 50},
{ field: 'text', headerName: 'Title', minWidth: 400 },
],
pagination: true,
paginationPageSize: 25,
defaultColDef: {
flex: 1,
editable: true,
},
rowData:[],
cacheQuickFilter: true,
rowSelection: 'single',
onGridReady: function(params) {
gridApi = params.api;
},
overlayLoadingTemplate: '<span class="ag-overlay-loading-center">Data Loading...</span>',
onSelectionChanged: onSelectionChanged,
}
async function initialize(url) {
myGridOptions.api.showLoadingOverlay();
let response = await getData(url);
// console.log(response);
const rowData = [];
var allData = response['oslc:results'].length;
// console.log(allData);
for (var i = 0; i < allData; i++) {
var item = {};
var text = response["oslc:results"][i]["oslc:label"];
item.id = text.substring(0, text.indexOf(':'));
item.text = text.substring(text.indexOf(':') + 1);
item.value = response["oslc:results"][i]["rdf:resource"];
item.title = response["oslc:results"][i]["rdf:type"];
var oslcResponse =
'oslc-response:{ "oslc:results":[{"koatl:apiUrl":"' +
response['oslc:results'][i]['koatl:apiUrl'] +
'", "oslc:label": "' +
response['oslc:results'][i]['oslc:label'] +
'", "rdf:resource": "' +
response['oslc:results'][i]['rdf:resource'] +
'", "rdf:type": "' +
response['oslc:results'][i]['rdf:type'] +
'"}]} ';
item.oslcResponse = oslcResponse;
rowData.push(item);
}
// console.log(rowData);
myGridOptions.api.hideOverlay();
// setup the grid after the page has finished loadin
myGridOptions.api.setRowData(rowData);
}
document.addEventListener('DOMContentLoaded', () => {
const gridDiv = document.querySelector('#myGrid');
new agGrid.Grid(gridDiv, myGridOptions);
});
function onSelectionChanged() {
const selectedRows = myGridOptions.api.getSelectedRows();
var oslcResponse = selectedRows[0].oslcResponse;
console.log(oslcResponse);
}
function onFilterTextBoxChanged() {
myGridOptions.api.setQuickFilter(
document.getElementById('filter-text-box').value
);
}
function onPrintQuickFilterTexts() {
myGridOptions.api.forEachNode(function (rowNode, index) {
console.log(
'Row ' +
index +
' quick filter text is ' +
rowNode.quickFilterAggregateText
);
});
}
async function getData(url) {
console.log(url);
const response = await fetch(`http://127.0.0.1:5000${url}`, {});
if (!response.ok) {
throw Error(response.statusText);
}
const data = await response.json();
return data;
}
我将此代码用于我的项目。我不明白重复的 myGridOption Declare 在哪里。我需要解决这个问题。我从 HTML 文件调用初始化,这就是为什么我不能在一个函数中添加所有函数。我不明白我该怎么办。我想解决这个语法错误。那不应该出现在控制台中。请帮我解决这个问题。