| Page 1 of 2 | [ 11 posts ] | Go to page 1, 2 Next |
|
Hi,
I'm new to YUI and I've a problem I can't solve: I'm using treeview with several entries which all have an id (labelElId, I'm not sure if this is right), a name (label) and an url. Code: var Node1 = new YAHOO.widget.TextNode({labelElId:'1',label:'first folder',href:'view.php?oid=1'}, root, false); var Node2 = new YAHOO.widget.TextNode({labelElId:'2',label:'second folder',href:'view.php?oid=2'}, root, false); var Node3 = new YAHOO.widget.TextNode({labelElId:'3',label:'third folder',href:'view.php?oid=3'}, root, false); var Node4 = new YAHOO.widget.TextNode({labelElId:'4',label:'first subfolder',href:'view.php?oid=4'}, Node3, false); .... If one of those folders is clicked a contextmenu appears with the possibility to remove that folder (I have used the code from http://developer.yahoo.com/yui/examples ... tmenu.html). All is working to this pint, but now I want to add an additional action to the remove function. The id of the deleted folder should be stored in a variable. But I don't know how to get access to the folder id in the contextmenu. Does anyone have a hint for my boiling brain? |
|
TreeView is a very old component in the library so it doesn't comply with some of the standards that the library has developed over its existence. Property labelElId should actually be marked private and have an leading underscore in its name, but that convention came later.
TextNode will ignore any value you give labelElId, it will force its own name. You can read the assigned id value from it, but you can't force a value into it. See: http://developer.yahoo.com/yui/treeview ... properties about how to store custom properties in a tree node and a few headings later, in responding to events, how to retrieve them. BTW, a plain number is not a valid value for an id, they should be proper identifiers, starting with a letter or underscore and followed by letters, underscores and numbers. Most browsers won't complain, but some obscure feature might fail. |
|
Thanks for your answer, but I'm still confused...
So, what steps do I have to do? 1. the treeview has to have the id in a proper way. I've changed the id name from labelElId to myNodeId and the value is now "o_1", "o_2"... hope that's correct now. 2. the contextmenu needs to get this parameter from the treeview Is this happening automatically or do I have to do it manually? 3. the contextmenu has to give the parameter to the delete function, so I can write the parameter value into a variable (I want to store all folders that are deleted in a value) How do I have to address the parameter from the contextmenu? Sorry, I'm new to YUI and I don't get along with the API documentation very well yet. |
|
Regarding,
1) If the value used were to be assigned to a DOM element ID, it should be a valid identifier, if it is a custom value with no relation to any DOM element ID then you are completely free to use any value and you may name it anyway you want. I can't help you much regarding how to use the context menu. TreeView is my thing, the rest, I am not sure. |
|
Hi,
it's a custom value. Here's what I try to do: the folders of the treemenu come from a database (they have an ID and a title). If one folder is deleted through the contextmenu it should be marked as deleted in the database too. To do this the contextmenu has to know the database ID of the folder, so this ID can be stored in a hidden textfield. |
Matt ParkerYUI Contributor
|
The example you're using sets the variable oCurrentTextNode when the ContextMenu shows. So if you're using the code from the example you'll have this object, which is the node, so you can get the id and do what you want with it before you remove the node. It should be pretty straightforward.
Matt |
|
Hello Matt,
yes, I do have the variable oCurrentTextNode, but it hasn't a value that I could use. f.e. it has the value "TextNode (1): first folder", "TextNode (2): another folder", "TextNode (3): another folder" ... The folders are unique by ID, not by title. And the "TextNode (x)" belongs to the treeview and not to the database entries (the number isn't the database ID). So, to mark the correct folder as deleted in the database, I need the unique ID the folder has in the database. |
Matt ParkerYUI Contributor
|
But haven't you followed Satyam's suggestion of storing the database id in a custom property above? Then surely you can get the id from there?
Matt |
|
Hi Matt,
yes, I stored the database ID in the parameter myNodeId in the treemenu. Code: var Node1 = new YAHOO.widget.TextNode({myNodeId:'1',label:'first folder',href:'view.php?oid=1'}, root, false); var Node2 = new YAHOO.widget.TextNode({myNodeId:'2',label:'second folder',href:'view.php?oid=2'}, root, false); var Node3 = new YAHOO.widget.TextNode({myNodeId:'3',label:'third folder',href:'view.php?oid=3'}, root, false); var Node4 = new YAHOO.widget.TextNode({myNodeId:'4',label:'first subfolder',href:'view.php?oid=4'}, Node3, false); .... But how do I get this parameter to the contextmenu? Sorry, I'm a real YUI newbie. |
Matt ParkerYUI Contributor
|
So in your deleteNode function (or whatever you're calling it - that's what it is in the example), oCurrentTextNode is an object. The things you list ("TextNode (1): first folder" etc) are string representations, but the object has all sorts of properties. So
Code: oCurrentTextNode.data.myNodeId will give you the id you need. |
| Page 1 of 2 | [ 11 posts ] | Go to page 1, 2 Next |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group