From d2aa40b9ebd3d93603a8d07061e689f8e39921db Mon Sep 17 00:00:00 2001 From: Alexander Shabunevich Date: Wed, 14 Feb 2024 17:52:26 +0300 Subject: [PATCH] feat: add data field to a TreeItem to store additional props --- src/lib/trilist.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/trilist.ts b/src/lib/trilist.ts index e9ecb85..63e7f24 100644 --- a/src/lib/trilist.ts +++ b/src/lib/trilist.ts @@ -16,6 +16,7 @@ export interface TreeItem { key: TreeItemKey label: string children?: TreeItem[] + data: any } type TreeItemHook = (item: TreeItem) => string @@ -239,10 +240,13 @@ export class Trilist { } protected processInputItem(item: InputItem, key = ''): TreeItem { + const { [this.fieldChildren]: _, ...data } = item // get data without children + const result: TreeItem = { id: item[this.fieldId].toString(), key: key ? key + '.' + item[this.fieldId] : item[this.fieldId].toString(), - label: item[this.fieldLabel] + label: item[this.fieldLabel], + data } if (item[this.fieldChildren] && item[this.fieldChildren].length) {