Skip to content

Commit

Permalink
feat: add data field to a TreeItem to store additional props
Browse files Browse the repository at this point in the history
  • Loading branch information
beholdr committed Feb 14, 2024
1 parent ed1f496 commit d2aa40b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/trilist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface TreeItem {
key: TreeItemKey
label: string
children?: TreeItem[]
data: any
}

type TreeItemHook = (item: TreeItem) => string
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d2aa40b

Please sign in to comment.