Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#10900 closed defect (fixed)

Tree: can't set path attribute to the root of the tree

Reported by: yveskurz Owned by: bill
Priority: high Milestone: 1.6
Component: Dijit Version: 1.4.2
Keywords: Cc:
Blocked By: Blocking:

Description

It's not possible to set the path of a dijit.Tree to the root of the tree.

For example: path = [ myStore.getRoot() ];

myTree.attr ('path', path);

This will fail because:

  1. myTree._setPathAttr() will remove the root item from path.(path now empty)
  2. myTree._setPathAttr() expands the root node and adds a callback to advance.
    1. advance() will be called back.
    2. advance() shifts the next item from path -> item = undefined
    3. since item is not a string it will try to get the identity from the model->store.
    4. this fails because item is undefined.

I think the problem is in 2) and can be solved by only adding a callback if path still contains elements. e.g instead of

this._expandNode(node).addCallback(dojo.hitch(this, advance));

possible (untested) solution:

var deferred = this._expandNode(node);
if (path.length) {
  deferred.addCallback(dojo.hitch(this, advance));
}

Change History (4)

comment:1 Changed 9 years ago by Simon Speich

I'm not sure, but I think your are wrong and this is not a bug. You can set the path to the root, but the path attribute expects an array with strings e.g. myTree.attr('path', /) or whatever the rootId of your tree is when you declared the model. Your myStore.getRoot() returns undefined? since there is no store.getRoot(). There is a model.getRoot(), which expects an onItem callback.

comment:2 Changed 9 years ago by bill

Milestone: tbd1.6
Owner: set to bill
Summary: Dijit.Tree: setting path attribute to the root of the treeTree: can't set path attribute to the root of the tree

Can reproduce the problem in test_Tree.html, doing:

dijit.byId("mytree").set("path", ["continentRoot"])

It gets stuck because the _setPathAttr() code is expecting at least two items in the array.

comment:3 Changed 9 years ago by bill

Resolution: fixed
Status: newclosed

(In [22498]) Fix corner case setting path to Tree's root node, fixes #10900 !strict.

comment:4 Changed 9 years ago by Pete Smith

Thanks, I patched my Tree.js with this revision and it fixed this problem exactly as advertised. Awaiting its release in 1.5.1?

httpete

Note: See TracTickets for help on using tickets.