Reputation: 3107
I have a dojo.data.ItemFileWriteStore object with items which contain a 'children' attribute, which in turn contains an array of children items. I'm storing a tree, and I need to fetch the leaf nodes from this tree. I have written a fetch method but it will not work giving it a query of "children: []" How can I fetch the data store items that have a children.length of 0 (the leaf nodes)? A blank array without adding attributes such as 'leaf' : bool to my items would obviously work, but I'd rather not have the extra attribute.
dojo.require(dojo.data.ItemFileWriteStore);
// A tree node with no children, these are the kind I want returned
// from the query!
var rootItem = {
children: []
};
var treeStore = new dojo.data.ItemFileWriteStore({
data: {
items: [rootItem]
}
});
//when dojo reaches one of its inner filtering methods
//there is a point where it calls dojo.some() to see
//which elements in the array to return which match the
//given items attribute, this is where it fails
treeStore.fetch({
query: {children: []},
queryOptions: {deep: true},
onComplete: function(leafItems) {
// All the items with no children here...
}
});
I also tried nesting a function for the attribute to no avail:
treeStore.fetch({
query: {
children: function(store, item){
return store.getValue(item, 'children').length == 0;
}
},
queryOptions: {deep: true},
onComplete: function(leafItems) {
// All the items with no children here...
}
});
Upvotes: 1
Views: 1839
Reputation: 6944
baseStore.fetch({
query:{id:'*'},
onComplete:function(a,b,c){
dojo.forEach(a,function(item,index){
console.log(item.children);
})
}
})
if item.children is undefined then those are the "item" that you want. If you don't want to use a separate fetch for this operation alone, then use a private property called _arrayOfAllItems on the store to get a flat data store, upon which you can do the same condition mentioned above.
Upvotes: 1