Bonjour à tous,

Décidement mes débuts avec Dojo sont chaotiques.Je voudrais pouvoir recharger un widget Tree après un clic sur un bouton.

J'ai donc une liste de boutons qui correspondent à la version des données à afficher dans le tree. L'url pour récupérer les données (JSON) va changer en fonction de cette version. Elle est de la forme "plans/v{version}" (par exemple "plans/v1" pour la version 1).
Le clic sur le bouton doit donc mettre à jour mon JSonRestStore avec la bonne url puis recharger le widget Tree.

Mais je n'y arrive pas...

Voici comment je créé mon Store et mon Tree
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Create the store
this.planItemsStore = new dojo.store.JsonRest({
	target:this.planItemsStoreTarget,
	clearOnClose:true,
	getChildren: function(object, onComplete, onError){
		//...
	},
	getLabel: function(object){
		//...
	},
	getRoot: function(onItem, onError){
		//...
	},
	mayHaveChildren: function(item){
		//...
	},
});
 
// Create the tree
this.planTree = new dijit.Tree({
	model: this.planItemsStore, // give it the model
	openOnClick:true,
	getIconClass: function(item, opened) {
		//...
	},
	onClick:dojo.hitch(this, function(item, node, evt){
		//...
	}),
},
"tree"); // target HTML element's id
 
this.planTree.startup();
Voici comment je mets à jour this.planItemsStore.target :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
this.planItemsStore.target = "ma_nouvelle_url";
J'ai trouvé ce bout de code sur Internet pour rafraichir un Tree :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Credit to this discussion: http://mail.dojotoolkit.org/pipermail/dojo-interest/2010-April/045180.html
// Close the store (So that the store will do a new fetch()).
this.planTree.model.store.clearOnClose = true;
this.planTree.model.store.close();
 
// Completely delete every node from the dijit.Tree     
this.planTree._itemNodesMap = {};
this.planTree.rootNode.state = "UNCHECKED";
this.planTree.model.root.children = null;
 
// Destroy the widget
this.planTree.rootNode.destroyRecursive();
 
// Recreate the model, (with the model again)
this.planTree.model.constructor(this.planTree.model);
 
// Rebuild the tree
this.planTree.postMixInProperties();
this.planTree._load();
Mais j'obtiens l'erreur suivante :
this.planTree.model.store is undefined
Quelqu'un a-t-il déjà rencontré le même problème?