In my AngularJS application, I have a page that displays multiple widgets. One widget shows a table with details about a monitored system. Currently, the table has two columns: 'Type' and 'Data', displaying information and values respectively.
To customize the widget's display, users can click the 'Settings' button to open a dialog. In this dialog, they can input column headings and rows for the table. When typing in the 'Rows' field, a dropdown appears with available variables matching the user's input.
The function responsible for the dropdown is:
$scope.autocompleteVarsFilter = function(query) {
if(!query && lastVarQryKw) {
query = lastVarQryKw;
}
var result = Object.keys(fxVar.getVars()).filter(function(name) {
return name.indexOf(query.toLowerCase()) !== -1;
});
if(result.length > 0) {
lastVarQryKw = query;
}
return result;
};
I want to add a third column to the table that will contain links chosen by the user. These links are denoted by strings starting with :
. The goal is to show all available pages when a user types :
followed by filtering based on their input.
I updated the function as follows:
$scope.autocompleteVarsFilter = function(query) {
if(query.startWith(":") {
var buttonsQuery = query.substring(1);
if(!buttonsQuery && lastVarQryKw) {
buttonsQuery = lastVarQryKw;
}
var userPages = pagesPresets;
console.log("Value of userPages: ", userPages);
var page;
for(page in userPages) {
console.log("for loop started");
if(page.key.startWith(buttonsQuery)) {
console.log("Matching page found: ", page);
}
}
if(result.length > 0) {
lastVarQryKw = query;
}
return result;
} else {
if(!query && lastVarQryKw) {
query = lastVarQryKw;
}
var result = Object.keys(fxVar.getVars()).filter(function(name) {
return name.indexOf(query.toLowerCase()) !== -1;
});
if(result.length > 0) {
lastVarQryKw = query;
}
return result;
}
};
After testing, I encountered an issue where the pages weren't displayed in the dropdown when typing :
. Console output showed a TypeError related to accessing the 'key' attribute of userpage objects.
I attempted different solutions like using forEach loops, but none resolved the issue. Anyone have suggestions?