pjekel / cbtree

The Dijit Tree with Multi State Checkboxes, project code 'cbtree' , is a highly configurable dojo/dijit tree with support for multi-state checkboxes or third party widgets capable of presenting a so-called 'checked' state.
Other
75 stars 34 forks source link

How to renew stores with each different data, thus refreshing tree. #49

Closed ClementYap closed 10 years ago

ClementYap commented 10 years ago

I am still looking for solutions or tips how to renew store with different set of data so that the tree is refreshed. Please advise. I am thinking of ..liken event or observable. like this as shown below but it does not work.

function refreshStore(givenBatch) { try { if (givenBatch.msg) { registry.byId("corner3").model.clearCache(); registry.byId("corner3").model.store.setData(givenBatch.msg); registry.byId("corner3").body.refresh(); } } catch (e) { alert("Error: When refreshing tree, " + e); } };

regards Clement

pjekel commented 10 years ago

First, there is not method model.clearCache(). Second, the method store.setData() is not observable. To refresh a cbtree you must use one of the cbtree stores and then reload the store, please see Reload Store

ClementYap commented 10 years ago

Wow... Many thanks. It works... Phew..... Thanks again

ClementYap commented 10 years ago

Hi, the first time it works. There are 2 buttons that each got data from mysql database by means of dojo.request. Both of the are working. I also have enabled property "clearOnClose". Whenever, the store is initialized, I am able to use both button to load the store for the first time. But in the second time, I again tried any button, the store is not loaded again.

Please see my function code:- function refreshStore(givenDB, givenCard, givenBatch) { request.post('list_tree.php', { data:{nameDB : givenDB, nameCard : givenCard, selectedBatch : givenBatch}, handleAs: "json" // JSON.parse is auto so JSON.parse is not needed ahead. }).then (function(response) { try { if(response.msg) { console.table(response.msg); console.debug("Loading into the store now!!"); storeA.close(); storeA.load({data:(response.msg), getChildren: function(object) { return this.query({parent: object.id}); } }); } } catch(e) { console.debug("Error: When refreshing tree, "+e); } }) }

The error prompted is "Error: When refreshing tree, TypeError: this.onLoadDeferred is undefined".