BernardChhun
2 Feb 2007, 12:51 PM
How can I assign a delegate to a freshly made a non-leaf AsyncTreeNode that has just been sended by the server?
here's my TreePanel:
http://img166.imageshack.us/img166/1329/arbreem4.png
The one labeled Favoris is an AsyncTreeNode so its children doesn't exist when the tree is rendered.
As you can see Favoris has 2 children: un dossier and une Fiche.
un dossier is another AsyncTreeNode so there's no problem there. It just needs to fetch its children from the PHP page.
I've been struggling to add a delegate on une Fiche. I tried adding a click property in the data sended by the php page like so :
[{ "text":"une Fiche",
"id":"1\/favoris\/1",
"cls":"fiche-node",
"leaf":true,
"click":"function coco(){alert('coco')}"}]
obviously this doesn't work as the click property will only be assigned to the TreeNode's attribute:
http://img65.imageshack.us/img65/8205/attributesdr5.png
Maybe I'm missing a property here I don't know.
I then thought of adding a delegate on the click event of the whole TreePanel. Using
myTreePanel.addListener('click', function(){
alert('Am I the one?')
if(this.selModel.selNode.attributes.data)
alert("it's the one!");
}.createDelegate(myTreePanel)
);
if you have noticed in the previous image, une Fiche has a data attribute. He's the only one to have that so I checked its existence in the function.
The thing that screw it all is that the click event of the whole TreePanel is considered as a selection only. That means that the "it's the one" alert won't show on the click event but on the dblClick event.
The thing that boggles my mind is that on the click event, this.selModel.selNode shows me the right TreeNode!!
I'm seriously thinking about controlling that AsyncTreeNode manually by converting it back to simple TreeNode and adding the click event delegate by hand. Before I do that, does anyone have an idea on how to delegate a function to that newly made TreeNode?
here's my TreePanel:
http://img166.imageshack.us/img166/1329/arbreem4.png
The one labeled Favoris is an AsyncTreeNode so its children doesn't exist when the tree is rendered.
As you can see Favoris has 2 children: un dossier and une Fiche.
un dossier is another AsyncTreeNode so there's no problem there. It just needs to fetch its children from the PHP page.
I've been struggling to add a delegate on une Fiche. I tried adding a click property in the data sended by the php page like so :
[{ "text":"une Fiche",
"id":"1\/favoris\/1",
"cls":"fiche-node",
"leaf":true,
"click":"function coco(){alert('coco')}"}]
obviously this doesn't work as the click property will only be assigned to the TreeNode's attribute:
http://img65.imageshack.us/img65/8205/attributesdr5.png
Maybe I'm missing a property here I don't know.
I then thought of adding a delegate on the click event of the whole TreePanel. Using
myTreePanel.addListener('click', function(){
alert('Am I the one?')
if(this.selModel.selNode.attributes.data)
alert("it's the one!");
}.createDelegate(myTreePanel)
);
if you have noticed in the previous image, une Fiche has a data attribute. He's the only one to have that so I checked its existence in the function.
The thing that screw it all is that the click event of the whole TreePanel is considered as a selection only. That means that the "it's the one" alert won't show on the click event but on the dblClick event.
The thing that boggles my mind is that on the click event, this.selModel.selNode shows me the right TreeNode!!
I'm seriously thinking about controlling that AsyncTreeNode manually by converting it back to simple TreeNode and adding the click event delegate by hand. Before I do that, does anyone have an idea on how to delegate a function to that newly made TreeNode?