Search code examples
c#javascriptasp.net-mvc-3dhtmlx

dhtmlxtoolbar option list, How to get specific Id based on Text?


Is it possible in dhtmlx to do a reverse lookup on an option list, i.e. if I know the ItemText can I use it to lookup the Id?

i.e. something like this if such a function existed

var t = this.getAllListOptionText("tbOptionList").indexOf(Name);

I want to get the id, so that I can preset the selection to a specific option.

I could potentially loop through all the options and look for the ItemText myself, however if something already exists that would be more elegant.

for (var i = 0; i < lsTags.length; i++) {
    if (this.getListOptionText("tbOptionList", lsTags[i]) == Name) {
        lOptionID = lsTags[i];
        break;
    }
}

Solution

  • There are dhtmlx methods forEachItem and forEachListOption, you can iterate items and use getItemText with a check.