tags:

views:

48

answers:

3

Hi All, I am rendering a Tree using Jason array that i get from a jsp page. So the tree has root node and 3 nodes and each node has more than 5 children and some of the children has same id and same text. It renders properly and no issues in display.

I am trying to make the user select child nodes of only one type (one of 3 nodes). if the user selects any node which is not the sibling of already existing node then i just need to un check already checked nodes. This sounds pretty simple and i coded it. I basically compared the parent nodes(node.parentNode.id) of the checked node with the already checked nodes(tree.getCheckedNodes())

the problem is when i select children nodes which have same id and text my logic fails and they say that they have same parentNode.id even though they have different parentNode.id. Does the tree panel check for duplicate elements and assign them to same parentnode while loading? what is going here and how to fix this any ideas. thank you.

    Ext.onReady(function(){
  var tree = new Ext.tree.TreePanel({
    id: 'deficiencyTree',
    renderTo: 'MyTable',
    title: 'Deficiencies',
    height: 'auto',
    width: 525,
    useArrows: true,
    autoScroll: true,
    animate: true,
    enableDD: true,
    containerScroll: true,
    rootVisible: false,
    frame: false,
    root:{nodeType: 'async'},
    dataUrl: 'jsonFile.jsp',
    listeners: {     
      'checkchange': function (node, checked) {

      if (checked) {
          selNodes = tree.getChecked();  
           alert(selNodes);      
          Ext.each(selNodes, function (nodes) {

     alert("id values for node and nodes "+node.parentNode.id+" "+nodes.parentNode.id);

           if (nodes.parentNode.id != node.parentNode.id) 
           {
             nodes.getUI().toggleCheck();               
            }       

          });
        }     
        list.length = 0;
        iii = 0;
        selNodess = tree.getChecked();
        Ext.each(selNodess, function (nodes) {
          list[iii] = nodes.id;
          iii++;
        });
      }
    }
  });
  tree.getRootNode().expand(false);
});
A: 

I used hierarhical ids to solve this problem: so if path to element was x->y->z then his id in tree will be x+y+z

you just need to change server-side code: - Get id in format x+y+z, find last + and get z - Return elements with ids [x+y+z+childId]

Xupypr MV
That sounds like a good logic, but i assigning the IDs from the database table ( primary Key value) and no way to change that. Please correct me if I understood your suggestion otherwise. thanks
A: 

As a semi-aside, ideally you should not be replicating node IDs at all (an ID should never be replicated, otherwise it isnt an ID). If you need the value that you are currently assigning to the ID field, add an additional attribute to the node and place it here- you can refer to this attribute when you need to. ExtJS isnt built to handle duplicate IDs for notes within the same tree very well at all.

Ergo Summary
Yes, I need that ID attribute later to save my selections in the database. so I tried putting a new attribute named ID2, along ID and text for each node, but when i tried to access it(node.ID2 like node.id, node.text) it says undefined. any idea how to access the new attribute? thanks.
A: 

Good news. I got it working. it was pretty simple. As "Xupypr MV" suggested, i shouldn't be using same ID which is against the basic functionality, so i did put a different id for each node and put a new attribute named id2 and assigned it the value i needed and then accessed it using node.attribute["id2"], and it work perfectly well. previously i tried to get the attribute value as node.id2 just like node.id, node.text which did not work. Thanks again for the responses.