Make optionSearch a little more generic, so children can be kept in sub-objects of any name not just 'value'

Changed to work with tree structure, which currently keep children in 'item'
This commit is contained in:
nathan 2024-02-14 10:41:22 -07:00
parent af7b4658e7
commit c6bf9954ae

View File

@ -172,20 +172,26 @@ export const Et2WidgetWithSelectMixin = <T extends Constructor<LitElement>>(supe
*
* @return SelectOption | null
*/
public optionSearch(value : string, options : SelectOption[] = null) : SelectOption | null
public optionSearch(value : string, options : SelectOption[] = null, childKey : string = "value") : SelectOption | null
{
let result = null;
let search = function(options, value)
{
return options.find((option) =>
{
if(Array.isArray(option.value))
if(!Array.isArray(option.value) && option.value == value)
{
return search(option.value, value);
result = option;
}
if(Array.isArray(option[childKey]))
{
return search(option[childKey], value);
}
return option.value == value;
});
}
return search(options ?? this.select_options, value);
search(options ?? this.select_options, value);
return result;
}
/**