Attach "value" object to an <sl-tree-item> #2394
Replies: 3 comments
-
Would be great to have a generic property on all components to attach custom objects to. @state() private node: TreeNode;
render() {
return html`<sl-tree-item data=${this.node} @click=${this.onClick}></sl-tree-item>`
) Then, on click, I would like to extract the custom object: onClick(event) {
console.log(event.target.data)
} |
Beta Was this translation helpful? Give feedback.
-
I realized
Works, but a bit of overhead and needs to be repeated for any tree which needs object retrieval on any event. |
Beta Was this translation helpful? Give feedback.
-
Correction:
I would suggest to define such a property on the superclass of all components. |
Beta Was this translation helpful? Give feedback.
-
I'm building a tree selector out of a tree of rich JavaScript objects. The component that renders the tree and its tree-items is not necessarily the one that receives the
sl-selection-change
event. It would be nice for the receiver to get the associated object(s). Because these are rich objects, converting to and from strings for use with adata-
property is inefficient.For now, I've done this by attaching it to the element and reading it off with explicit casting:
and
Does anyone have another idea? Is this a concept that's worth adding to the library?
Beta Was this translation helpful? Give feedback.
All reactions