0

I am able to render a tree using YAHOO.widget.TreeView yui 2.9. Using pre made

tags
<ul> <li> Products </li> </ul>

I am able to get the label i.e Products using node.label

YAHOO.util.Event.on('allProductSaveButton','click',function() { 

    var hiLit = rightProductTree.getNodesByProperty('highlightState',1);

    if (YAHOO.lang.isNull(hiLit)) {  

        YAHOO.log("None selected"); 

    } else { 
        var labels = []; 



        for (var i = 0; i < hiLit.length; i++) {

               var node = hiLit[i];

               if(node.children.length<=0) {

            labels.push(hiLit[i].label); }
        } 
        alert("Highlighted nodes:\n" + labels.join("\n"), "info", "example"); 
    } 
});

I want to insert id of the Products in the html and get the id of label as well. so where should I place id attribute inside

  • or where?
  • 2 Answers2

    0

    I am not sure you can set your own id on the markup. TreeView is one of the oldest widgets in YUI 2 and it uses a particularly funny markup because the supported CSS styles in those days were quite pathetic, thus, what part of that funny markup are you going to apply that id to?

    If what you want is to give a tree-node an identifier that you can later use to retrieve it, then use custom properties. Then, calling getNodesByProperty will allow you to retrieve the node by the value of that extra property.

    user32225
    • 854
    • 7
    • 7
    0

    I got a solution. I inserted the label element inside the span element that was inside the li element i.e

     <ul>
        <li> <span> <label id="444" > Product </label> </span>
          </li>
         </ul>
    

    then using YAHOO.util.Dom I traversed and got the id attribute of label element.

    YAHOO.util.Event.on('GroupsProductSaveButton', 'click', function() {
                var hiLit = rightProductTree2.getNodesByProperty('highlightState', 1);
                if (YAHOO.lang.isNull(hiLit)) {
                    alert("None selected");
                } else {
                    var labels = [];
    
           for (var i = 0; i < hiLit.length; i++) {
    
                   var node = hiLit[i];
    
                   if(node.children.length<=0) {                
                           labels.push(YAHOO.util.Dom.get(hiLit[i].contentElId).getElementsByTagName('label')[0].getAttribute("value")); }
            }  
                    alert("Highlighted nodes:\n" + labels.join("\n"), "info", "example");
    
                    ProductGroupDWR.displaySelectedNodes(labels, function(data) {
    
                    });
                }
            });