mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-14 01:48:35 +01:00
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:
parent
af7b4658e7
commit
c6bf9954ae
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user