You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.
I was trying to use the node returned from event hooks (e.g. onNodeSelected(event, node)) as parent and to add a child to that parent without success. Here is an emulating code of what i was doing.
The cause of that is the node returned from the hook is a deep copy. See below code
// ...
this._triggerEvent('nodeSelected', node, options);
// ...
Tree.prototype._triggerEvent = function (event, data, options) {
if (options && !options.silent) {
// $.extend(true, {}, data) is a deep copy of the original node.
this.$element.trigger(event, $.extend(true, {}, data));
}
}
So, adding child is to add child to the copy which has no effect to the tree.
The issue can be worked around by getting the original node (see below). Wound it be better to return the original copy? Is it intentional to return a replicate over original to avoid internal data structure being messed up? Thanks.
$("#tree").treeview({
// ...
onNodeSelected: function (event, node) {
var folder = {
name: "child",
// ...
};
var parent = $("#tree").treeview(true).findNodes(node.id, "id");
$("#tree").treeview(true).addNode(folder, parent);
},
// ...
}
The text was updated successfully, but these errors were encountered:
I was facing the same issue while trying to unselect the deep copied node inside the "onNodeSelected" event. The 'getSelected' method kept returning the unselected node even though the 'selected' class was removed from the html element.
I was trying to use the node returned from event hooks (e.g.
onNodeSelected(event, node)
) as parent and to add a child to that parent without success. Here is an emulating code of what i was doing.The cause of that is the
node
returned from the hook is a deep copy. See below codeSo, adding child is to add child to the copy which has no effect to the tree.
The issue can be worked around by getting the original node (see below). Wound it be better to return the original copy? Is it intentional to return a replicate over original to avoid internal data structure being messed up? Thanks.
The text was updated successfully, but these errors were encountered: