diji.Tree + JsonRestStore - selecting node program

2019-05-24 23:38发布

问题:

I've this problem. I'm using dijit.Tree with dojox.data.JsonRestStore as datasource. All nodes are lazy loaded. When I try to programmatically select a node using tree.set("path", [1,2]) I get an error saying "Could not expand path at undefined"

Is it possible to use tree.set("path"...) when the tree structure is being loaded dynamically ?

My code contains 2 files. source.php is the implementation of data source

  1. tree.php is available here http://jsfiddle.net/hd2MZ/2/

  2. source.php is available here http://jsfiddle.net/6zu3d/

Please help :)

回答1:

I see a couple potential issues...

  1. You need to specify the path to the desired node starting at the root node.
  2. You are using the ForestStoreModel which creates a root node under the covers, since you did not specify the id for the root node when initializing the model, the ForestStoreModel by default will use '$root$' as the id for the root node.
  3. I believe id's for items in the data store are strings... not integers.

... where you are trying to set the path I would try the following:

tree.set("path", ['$root$', '1', '2']);