-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ability to update data through an update method #141
Conversation
It is not obvious that this method updates the |
@amsik Good point. That may be a good idea. this.$refs.tree.update('Item 1', node => {
return {
data: { text: 'Item 2' },
state: { selected: true }
}
}); What do you think? This way, if there was ever more "updatable" properties in the Node object, we could easily allow that and have one method for them all instead of Just to make it even more clear, if you just do: this.$refs.tree.update('Item 1', node => {
return {
data: { text: 'Item 2' }
}
}); The |
Please take a look at the next code: select (extendList) {
if (!this.selectable() || this.selected()) {
return this
}
this.tree.select(this, extendList)
this.state('selected', true)
this.$emit('selected')
return this
} Code above shows how |
@amsik - I'll look into this as soon as I have some spare time :) |
Thanks for your contributing! I'll do as well :) |
Looking forward to this. I agree that For now I wrote a workaround where I iterate current model and and call |
Jeeez I totally forgot about this. I'll try to look into this in the next few days but no promises 🤣 |
I have updated the PR. I decided to take your advice and rename the method to this.$refs.tree.updateData('Item 1', node => {
node.select();
return { text: 'Item 2' };
}); |
Any feedback @amsik? |
I have quite frequently ran into a situation where I was using the "data" object on a node for various reasons. I ran into a situations where I wanted to update the X amount of nodes at the same time so I would first have to find them, loop through them and update a specific value and this approach felt cumbersome.
So I thought it would be nice to have a method to update the data object on a given node. The reason why it's just the data object and not other things is because that's the only object that can be safely updated without unintended consequences + we already have other helpers for nodes like select, unselect etc to update the state.
The way you use it is like this:
The first argument of the
update
method is exactly the same as the argument in thefind
method where it's the criteria. So it can be RegExp or just a string to match the text. Second argument is callback which gives you access to each of the nodes that matched the criteria. The return statement in the callback is what is added to the data object of the node. So you could even override the text by simply doing: