diff --git a/app/components/pub/my-ui/combobox/index.ts b/app/components/pub/my-ui/combobox/index.ts index 82a3b3cd..e4864f7f 100644 --- a/app/components/pub/my-ui/combobox/index.ts +++ b/app/components/pub/my-ui/combobox/index.ts @@ -20,4 +20,17 @@ export function recStrToItem(input: Record): Item[] { return items } +export function objectsToItems(input: object[], key = 'id', label = 'name'): Item[] { + const items: Item[] = [] + for (const item of input) { + if (item.hasOwnProperty(key) && item.hasOwnProperty(label)) { + items.push({ + value: item[key as keyof typeof item], // the hasOwnProperty check should be enough + label: item[label as keyof typeof item], // the hasOwnProperty check should be enough + }) + } + } + return items +} + export { default as Combobox } from './combobox.vue'