开发者

ExtJS Tree same parentNode

开发者 https://www.devze.com 2023-01-22 17:09 出处:网络
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 t开发者_JAVA技巧he children has same id and

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 t开发者_JAVA技巧he 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);
});


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.


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]


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消