Quantcast

New object store and dijit.Tree

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

New object store and dijit.Tree

Anton Krasovsky
Guys,

is there any examples of using new Dojo Object Store API with
dijit.Tree/TreeModel?

Regards,
Anton
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

José Moreira-2
http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/tree/Tree.html ?

it uses dojo.data.ItemFileWriteStore

2011/3/14 Anton Krasovsky <[hidden email]>:

> Guys,
>
> is there any examples of using new Dojo Object Store API with
> dijit.Tree/TreeModel?
>
> Regards,
> Anton
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>



--
http://zemanel.eu
http://github.com/zemanel
http://pt.linkedin.com/in/josemoreira
http://djangopeople.net/josemoreira
irc://[hidden email]
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Anton Krasovsky
Well, I'm looking for an example that uses new 'dojo.store' API
available in 1.6 beta, which is different from 'dojo.data' used in the
test.

Anton

2011/3/14 José Moreira <[hidden email]>:

> http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/tree/Tree.html ?
>
> it uses dojo.data.ItemFileWriteStore
>
> 2011/3/14 Anton Krasovsky <[hidden email]>:
>> Guys,
>>
>> is there any examples of using new Dojo Object Store API with
>> dijit.Tree/TreeModel?
>>
>> Regards,
>> Anton
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> [hidden email]
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>
>
>
> --
> http://zemanel.eu
> http://github.com/zemanel
> http://pt.linkedin.com/in/josemoreira
> http://djangopeople.net/josemoreira
> irc://[hidden email]
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Kenneth G. Franqueiro
Personally I'd be interested in this as well - mainly because although I
see that the dojo.store spec calls for an optional `getChildren` method,
I don't think any of the stores OOTB in Dojo 1.6 actually implement it.

I also don't see any specified equivalent to the parentInfo argument of
dojo.data.Write's newItem function, so I'm wondering how one is intended
to add children to a dojo.store.

But perhaps more to the point of the original question, I don't think
any existing widgets have been converted to use dojo.store yet.  I think
a few might get looked at for 1.7.  You can try your luck at pointing a
Tree at a dojo.store running through dojo.data.ObjectStore, which will
attempt to translate dojo.store API calls to dojo.data API calls.

--Ken

On 3/14/2011 7:47 PM, Anton Krasovsky wrote:

> Well, I'm looking for an example that uses new 'dojo.store' API
> available in 1.6 beta, which is different from 'dojo.data' used in the
> test.
>
> Anton
>
> 2011/3/14 José Moreira<[hidden email]>:
>> http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/tree/Tree.html ?
>>
>> it uses dojo.data.ItemFileWriteStore
>>
>> 2011/3/14 Anton Krasovsky<[hidden email]>:
>>> Guys,
>>>
>>> is there any examples of using new Dojo Object Store API with
>>> dijit.Tree/TreeModel?
>>>
>>> Regards,
>>> Anton
>>> _______________________________________________
>>> FAQ: http://dojotoolkit.org/support/faq
>>> Book: http://docs.dojocampus.org
>>> [hidden email]
>>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>
>>
>>
>>
>> --
>> http://zemanel.eu
>> http://github.com/zemanel
>> http://pt.linkedin.com/in/josemoreira
>> http://djangopeople.net/josemoreira
>> irc://[hidden email]
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> [hidden email]
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Simon Speich
In reply to this post by Anton Krasovsky
I haven't tried it myself yet, but there is an adapter for this:
http://docs.dojocampus.org/dojo/data/ObjectStore
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Anton Krasovsky
The ObjectStore adaptor works well with the likes of Grid, but it
didn't work for me in the Tree, where I'm  especially interested in
lazy loading of the tree children.

Anton

On Tue, Mar 15, 2011 at 7:32 AM, Simon Speich <[hidden email]> wrote:

> I haven't tried it myself yet, but there is an adapter for this:
> http://docs.dojocampus.org/dojo/data/ObjectStore
>
>
> --
> View this message in context: http://dojo-toolkit.33424.n3.nabble.com/New-object-store-and-dijit-Tree-tp2680201p2680939.html
> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

José Moreira-2
i think you can create a Tree model to adapt to the 1.6 stores

2011/3/15 Anton Krasovsky <[hidden email]>:

> The ObjectStore adaptor works well with the likes of Grid, but it
> didn't work for me in the Tree, where I'm  especially interested in
> lazy loading of the tree children.
>
> Anton
>
> On Tue, Mar 15, 2011 at 7:32 AM, Simon Speich <[hidden email]> wrote:
>> I haven't tried it myself yet, but there is an adapter for this:
>> http://docs.dojocampus.org/dojo/data/ObjectStore
>>
>>
>> --
>> View this message in context: http://dojo-toolkit.33424.n3.nabble.com/New-object-store-and-dijit-Tree-tp2680201p2680939.html
>> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> [hidden email]
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>



--
http://zemanel.eu
http://github.com/zemanel
http://pt.linkedin.com/in/josemoreira
http://djangopeople.net/josemoreira
irc://[hidden email]
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Anton Krasovsky
Yeah, I guess you're right. I'll give it a shot.

Anton

2011/3/15 José Moreira <[hidden email]>:

> i think you can create a Tree model to adapt to the 1.6 stores
>
> 2011/3/15 Anton Krasovsky <[hidden email]>:
>> The ObjectStore adaptor works well with the likes of Grid, but it
>> didn't work for me in the Tree, where I'm  especially interested in
>> lazy loading of the tree children.
>>
>> Anton
>>
>> On Tue, Mar 15, 2011 at 7:32 AM, Simon Speich <[hidden email]> wrote:
>>> I haven't tried it myself yet, but there is an adapter for this:
>>> http://docs.dojocampus.org/dojo/data/ObjectStore
>>>
>>>
>>> --
>>> View this message in context: http://dojo-toolkit.33424.n3.nabble.com/New-object-store-and-dijit-Tree-tp2680201p2680939.html
>>> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
>>> _______________________________________________
>>> FAQ: http://dojotoolkit.org/support/faq
>>> Book: http://docs.dojocampus.org
>>> [hidden email]
>>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> [hidden email]
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>
>
>
> --
> http://zemanel.eu
> http://github.com/zemanel
> http://pt.linkedin.com/in/josemoreira
> http://djangopeople.net/josemoreira
> irc://[hidden email]
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Anton Krasovsky
I've implemented minimal ThreeModel on top of dojo.store.JsonRest
store and it was much easier then I expected.

I'm attaching an example here, it expects the server-side to supply
objects that look like:
{name:<object id>, children: [<object id>, <object id>, ....] with the
root object having name of '0'.

Anton

On Tue, Mar 15, 2011 at 10:38 AM, Anton Krasovsky
<[hidden email]> wrote:

> Yeah, I guess you're right. I'll give it a shot.
>
> Anton
>
> 2011/3/15 José Moreira <[hidden email]>:
>> i think you can create a Tree model to adapt to the 1.6 stores
>>
>> 2011/3/15 Anton Krasovsky <[hidden email]>:
>>> The ObjectStore adaptor works well with the likes of Grid, but it
>>> didn't work for me in the Tree, where I'm  especially interested in
>>> lazy loading of the tree children.
>>>
>>> Anton
>>>
>>> On Tue, Mar 15, 2011 at 7:32 AM, Simon Speich <[hidden email]> wrote:
>>>> I haven't tried it myself yet, but there is an adapter for this:
>>>> http://docs.dojocampus.org/dojo/data/ObjectStore
>>>>
>>>>
>>>> --
>>>> View this message in context: http://dojo-toolkit.33424.n3.nabble.com/New-object-store-and-dijit-Tree-tp2680201p2680939.html
>>>> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
>>>> _______________________________________________
>>>> FAQ: http://dojotoolkit.org/support/faq
>>>> Book: http://docs.dojocampus.org
>>>> [hidden email]
>>>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>>
>>> _______________________________________________
>>> FAQ: http://dojotoolkit.org/support/faq
>>> Book: http://docs.dojocampus.org
>>> [hidden email]
>>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>
>>
>>
>>
>> --
>> http://zemanel.eu
>> http://github.com/zemanel
>> http://pt.linkedin.com/in/josemoreira
>> http://djangopeople.net/josemoreira
>> irc://[hidden email]
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> [hidden email]
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

TreeModel.js (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Bill Keese-2
Glad you got it working.   Note though that you design will fire a separate XHR for every child node, looks inefficient a.k.a. slow.

On Wed, Mar 16, 2011 at 12:24 AM, Anton Krasovsky <[hidden email]> wrote:
I've implemented minimal ThreeModel on top of dojo.store.JsonRest
store and it was much easier then I expected.

I'm attaching an example here, it expects the server-side to supply
objects that look like:
{name:<object id>, children: [<object id>, <object id>, ....] with the
root object having name of '0'.

Anton

On Tue, Mar 15, 2011 at 10:38 AM, Anton Krasovsky
<[hidden email]> wrote:
> Yeah, I guess you're right. I'll give it a shot.
>
> Anton
>
> 2011/3/15 José Moreira <[hidden email]>:
>> i think you can create a Tree model to adapt to the 1.6 stores
>>
>> 2011/3/15 Anton Krasovsky <[hidden email]>:
>>> The ObjectStore adaptor works well with the likes of Grid, but it
>>> didn't work for me in the Tree, where I'm  especially interested in
>>> lazy loading of the tree children.
>>>
>>> Anton
>>>
>>> On Tue, Mar 15, 2011 at 7:32 AM, Simon Speich <[hidden email]> wrote:
>>>> I haven't tried it myself yet, but there is an adapter for this:
>>>> http://docs.dojocampus.org/dojo/data/ObjectStore
>>>>
>>>>
>>>> --
>>>> View this message in context: http://dojo-toolkit.33424.n3.nabble.com/New-object-store-and-dijit-Tree-tp2680201p2680939.html
>>>> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
>>>> _______________________________________________
>>>> FAQ: http://dojotoolkit.org/support/faq
>>>> Book: http://docs.dojocampus.org
>>>> [hidden email]
>>>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>>
>>> _______________________________________________
>>> FAQ: http://dojotoolkit.org/support/faq
>>> Book: http://docs.dojocampus.org
>>> [hidden email]
>>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>
>>
>>
>>
>> --
>> http://zemanel.eu
>> http://github.com/zemanel
>> http://pt.linkedin.com/in/josemoreira
>> http://djangopeople.net/josemoreira
>> irc://[hidden email]
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> [hidden email]
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Simon Speich
@Bill: What would be a better solution then? I've been using the dojo.data.JsonRestStore with references ($ref) and would like to switch to the new dojo.store.JsonRest also. If I'm not mistaken JsonRestStore combined with a tree does the same, e.g. issue a request for each child of a tree node.

@Anton: I've extend your example a bit to support any kind of root and children nodes by. Furthermore you can set it to only show nodes in the tree, when they have children. It also fulfills the dojo.store.JsonRest's requirement that "The JsonRest expects the results to be returned in an array (not in an object with an items property like some stores" for the first request.
this.store = new dojo.store.JsonRest({...});
this.treeModel = new rfe.TreeStoreModel({
	store: this.store,
	childrenAttr: 'dir',
	showOnlyChildren: true,
	rootId: '/'
});

dojo.provide('rfe.TreeStoreModel');
dojo.declare('rfe.TreeStoreModel', null, {
	root: null,
	rootId: '/',
	childrenAttr: 'dir',
	showOnlyChildren: true,

	constructor: function(args) {
		dojo.mixin(this, args);
	},

	getRoot: function(onItem) {
		dojo.when(this.store.get(this.rootId), function(item) {
			this.root = item[0];
			onItem(this.root);
		});
	},

	getLabel: function(item) {
		return item.name;
	},

	mayHaveChildren: function(item) {
		return item[this.childrenAttr] && item[this.childrenAttr].length > 0;
	},

	getIdentity: function(item) {
		return item.id;
	},

	getChildren: function(parentItem, onComplete) {
		var children = parentItem[this.childrenAttr];
		var len = children.length;
		var childItems = [];

		children.forEach(function(childId) {
			var self = this;
			dojo.when(this.store.get(childId), function(child) {
				if (self.showOnlyChildren && child[self.childrenAttr]) {  // only display directories in the tree
					childItems.push(child);
				}
				len--;
				if (len == 0) {
					onComplete(childItems);
				}
			});
		}, this);
	}
});

// servers response for root
[{"id":"\/","name":"my Folders","size":0,"mod":"21.03.2010","dir":["\/1","\/2","\/3","\/4"]}]
// for each item
{"id":"\/1","name":"folder 1","size":0,"mod":"21.03.2010","dir":["\/1\/photo01.jpg","\/1\/photo02.jpg","\/1\/photo03.jpg"]}


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Bill Keese-2
Well I was thinking of a single request to get all the children, doing away with those $ref things altogether... I didn't think over the details, it could be a special URL or maybe just a query for nodes with parent = 1234

On Sun, Mar 20, 2011 at 12:29 AM, Simon Speich <[hidden email]> wrote:
@Bill: What would be a better solution then? I've been using the
dojo.data.JsonRestStore with references ($ref) and would like to switch to
the new dojo.store.JsonRest also. If I'm not mistaken JsonRestStore combined
with a tree does the same, e.g. issue a request for each child of a tree
node.

@Anton: I've extend your example a bit to support any kind of root and
children nodes by. Furthermore you can set it to only show nodes in the
tree, when they have children. It also fulfills the dojo.store.JsonRest's
requirement that "The JsonRest expects the results to be returned in an
array (not in an object with an items property like some stores" for the
first request.

this.store = new dojo.store.JsonRest({...});
this.treeModel = new rfe.TreeStoreModel({
       store: this.store,
       childrenAttr: 'dir',
       showOnlyChildren: true,
       rootId: '/'
});

dojo.provide('rfe.TreeStoreModel');
dojo.declare('rfe.TreeStoreModel', null, {
       root: null,
       rootId: '/',
       childrenAttr: 'dir',
       showOnlyChildren: true,

       constructor: function(args) {
               dojo.mixin(this, args);
       },

       getRoot: function(onItem) {
               dojo.when(this.store.get(this.rootId), function(item) {
                       this.root = item[0];
                       onItem(this.root);
               });
       },

       getLabel: function(item) {
               return item.name;
       },

       mayHaveChildren: function(item) {
               return item[this.childrenAttr] && item[this.childrenAttr].length > 0;
       },

       getIdentity: function(item) {
               return item.id;
       },

       getChildren: function(parentItem, onComplete) {
               var children = parentItem[this.childrenAttr];
               var len = children.length;
               var childItems = [];

               children.forEach(function(childId) {
                       var self = this;
                       dojo.when(this.store.get(childId), function(child) {
                               if (self.showOnlyChildren && child[self.childrenAttr]) {  // only
display directories in the tree
                                       childItems.push(child);
                               }
                               len--;
                               if (len == 0) {
                                       onComplete(childItems);
                               }
                       });
               }, this);
       }
});

// servers response for root
[{"id":"\/","name":"my
Folders","size":0,"mod":"21.03.2010","dir":["\/1","\/2","\/3","\/4"]}]
// for each item
{"id":"\/1","name":"folder
1","size":0,"mod":"21.03.2010","dir":["\/1\/photo01.jpg","\/1\/photo02.jpg","\/1\/photo03.jpg"]}





--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/New-object-store-and-dijit-Tree-tp2680201p2702362.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Simon Speich
How about a hierarchical restful style for the ids, e.g.:
/{id} would query for an item and
/{id}/ would query for its children
/{id}/{id}
/{id}/{id}/
...

store.get('/1');
server would respond with
{id: '/1', dir: true}

store.get('/1/');  // note the trailing slash
server responds with
[{id: '/1/1', parentId: '/1'},     // or maybe only {id: '/1/1'} to keep transmitted data small
{id: '/1/2', parentId: '/1'},
{id: '/1/3', parentId: '/1'}]

This would allow for taking an item.id, then if item.dir === true then add a slash and do store.query({parentId: item.id + '/'}) to fetch its children (what's the difference then to store.get(item.id + '/') then, caching? Because I wouldn't even need the parentId attribute since the parent id is contained in the child id.).

What would store.Cache cache, the individual children ids or the request id?
Would all the great dojo.data things such deleting, adding, updating work?
What about tree dnd?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Simon Speich
To answer my own question about drag an drop: Don't use the id to extract the parentId even if you are using a pathlike structure .e.g., getting parentId: '/1/' from id: '/1/1', because if you move a child (node in tree) to another node you are lost, since parent is now different path. Kind of obvious, though...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

ge72
This post has NOT been accepted by the mailing list yet.
Hi and thank you for your posting above.

I have a similar problem with the new (1.6) dojo tree model
I try to get the tree data from a JsonRest on my server.

I am getting an error that there is a problem rendering the tree and I think it is to do with the model because when I don't have {children: []} in the json the error is gone.

I have 4 components
var store = dojo.store.,JsonRest ({...});
var data = dojo.data.ObjectStore({store: store, ...});
var model = dijit.tree.TreeStoreModel({store: data, ...});
var tree = dijit.Tree({model: model, ...});

the tree root always renders but when I have children: [] element in the json I get the following error:

Node cannot be inserted at the specified point in the hierarchy"  code: "3
http://localhost:8080/ ... /dojo/dojo.js
Line 14

Any idea what to do?
many thanks.
G.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Simon Speich
I don't know what's causing your error, but I suggest you get rid of the ObjectStore and the TreeStoreModel altogether. It's kind of an overkill to use the ObjectStore with the JsonRest and the tree (you could use the old JsonRestStore then). Instead just add the methods getRoot(), getLabel(), mayHaveChildren(), getChildren() to your store and you can use the store directly on the tree without the ObjectStore and the Model. Below is the code I'm using. The getChildren method is for use with the StoreCache and to filter items that don't have children, but it should be easy to adapt it to your needs.


getRoot: function(onItem) {
	dojo.when(this.get(this.rootId), function(item) {
		this.root = item;
		onItem(this.root);
	});
},

getLabel: function(item) {
	return item[this.labelAttr];
},

mayHaveChildren: function(item) {
	return item[this.childrenAttr];
},

getChildren: function(item, onComplete, onError) {
	var self = this, query;
	var childItems, children;
	var obj = {};
	var id = item[this.idProperty];
	var dfd = new dojo.Deferred();

	obj[this.parentAttr] = id;
	children = this.storeMemory.query(obj);

	// Children are available e.g. already cached in storeMemory
	if (children.length > 0) {
		if (self.skipWithNoChildren) {
			childItems = children.filter(function(child) {
				if (child[self.childrenAttr]) {  // only display directories in the tree
					return true;
				}
			});
		}
		else {
			childItems = children;
		}
		if (onComplete) {
			onComplete(childItems);
		}
		dfd.resolve(childItems);
	}
	// Items not cached yet, add them to the storeCache
	else {
		query = self.storeMaster.query(id + '/');
		// TODO: enable as soon as bug http://bugs.dojotoolkit.org/ticket/12835 is fixed
		//query.observe(dojo.hitch(this, self.observeChildren));
		dfd = dojo.when(query, function(children) {
			for (var i = 0, len = children.length; i < len; i++) {
				self.storeMemory.put(children[i]);
			}
			if (self.skipWithNoChildren) {
				childItems = dojo.filter(children, function(child) {
					if (child[self.childrenAttr]) {  // only display directories in the tree
						return true;
					}
				});
			}
			else {
				childItems = children;
			}
			if (onComplete) {
				onComplete(childItems);
			}
			return childItems;
		})
	}
	return dfd;
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

ge72
This post has NOT been accepted by the mailing list yet.
Thanks Simon,

is this code extension to JsonRestStore?
should I do this...

// file rds/store/Tree
dojo.provide('rds.store.Tree');

dojo.require("dojox.data.JsonRestStore")

dojo.declare('rds.store.Tree', dojox.data.JsonRestStore, {
   
    root                : null,
    rootId              : 'entity',
    childrenAttr        : 'cildren',
    showOnlyChildren    : true,
   
    constructor: function(args) {
        dojo.mixin(this, args);
        console.debug("rds.store.Tree:constructor");
    },

    getRoot: function(onItem) {
        dojo.when(this.store.get(this.rootId), function(item) {
            this.root = item[0];
            onItem(this.root);
        });
    },

    getLabel: function(item) {
        return item.name;
    },

    mayHaveChildren: function(item) {
        return item[this.childrenAttr] && item[this.childrenAttr].length > 0;
    },

    getIdentity: function(item) {
        return item.id;
    },

    getChildren: function(parentItem, onComplete) {
        var children = parentItem[this.childrenAttr];
        var len = children.length;
        var childItems = [];

        children.forEach(function(childId) {
            var self = this;
            dojo.when(this.store.get(childId), function(child) {
                if (self.showOnlyChildren && child[self.childrenAttr]) {  // only display directories in the tree
                    childItems.push(child);
                }
                len--;
                if (len == 0) {
                    onComplete(childItems);
                }
            });
        }, this);
    }
});

thanks in advance,
G.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Simon Speich
Nope, now you got different things mixed up. Maybe I wasn't clear enough. There are two types of store apis in dojo now (since 1.6). On the one hand is the "old school" dojo.data.api, which supports the tree and the grid out of the box because of it's many features, but comes with quite some complexity. On the other hand there is the new dojo.store api, which is not yet supported by the tree or the grid, but its simpler to use, basically because of its direct object property access.

So in your case you either go with the dojo.data.api and use the dojox.data.JsonRestStore together with the dijit.tree.TreeStoreModel or you choose the new dojo.store.JsonRest, but have to extend it to work with the tree. My code extends the dojo.store.Cache which uses a dojo.store.Memory and a dojo.store.JsonRest:
dojo.provide('rfe.StoreFileCache');

dojo.require('dojo.store.Observable');
dojo.require('dojo.store.Cache');

dojo.declare('rfe.StoreFileCache', null, {
	storeMaster: null,
	storeMemory: null,
	childrenAttr: 'dir',
	parentAttr: 'parId',
	labelAttr: 'name',
	rootId: 'root',
	skipWithNoChildren: true, // getChildren returns only folders

	constructor: function(storeMaster, storeMemory, options) {
		var storeCache;
//		this.storeMaster = new dojo.store.Observable(storeMaster);
		this.storeMaster = storeMaster;
		this.storeMemory = storeMemory;
		storeCache = new dojo.store.Cache(this.storeMaster, this.storeMemory);

		dojo.safeMixin(this, storeCache);
		dojo.safeMixin(this, options);
	},

	getRoot: function() {};
	},
...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

Karl Tiedt
why would you mixin a "getChildren" to a store?

just write a simple recursive function that uses tree.rootNode.getChildren() ?

-Karl Tiedt
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: New object store and dijit.Tree

ge72
This post has NOT been accepted by the mailing list yet.
In reply to this post by Simon Speich
Thanks Simon, This is much clearer.

Let me try and describe my scenario better.

I have a DataGrid and a Tree in the same frame/border container.

1. Data is loaded to the table representing server records
2. the tree is displayed when the user select a row from the table, using the record id. the tree is the record from the table with all the relational data.
3. each time the user select a different row the JsonRest need to retrieve a new json tree data from the server
4. this data is now attached to the tree and the tree is refreshed/created

so far my understanding was I need to destroy the tree and create it again because tree cannot be refreshed in any way. using my old example I kept the JsonRest and the ObjectStore and just created a new TreeModel with the new query (server url localhost / <path> / record-id ) and a new Tree and got the original error in my first post.

Following your suggestion I removed the ObjectStore and created your cache class with memory object. I don't think I need the cache as each time the data is completely different. I also need a way to tell the model the url has changed and to get the new data from the server. Before that was handled by the ObjectStore with the setQuery( url ).

I think I need a simpler solution where the tree model talk to the jsonRest directly and I can replace the URL each time the user select a different row from the datagrid.

maybe (forgive my lack of understanding) I need to keep the ObjectStore/JsonRest configuration for calling the server for data and just create a custom tree data model to fit the tree?

Many thanks in advance. at least we have an interesting conversation :)
G.



 


12
Loading...