Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-736

tree's getSelectedItem() always return wrong value

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 6.0.0
    • 6.0.0, Freshly
    • Components

      Reproducing steps:

      1. run test case as follows:
        <zk>
        	<zscript><![CDATA[
        	public class MyModel extends AbstractTreeModel {
        		public MyModel() {
        			super("Root");
        		}
        
        		public boolean isLeaf(Object node) {
        			return getLevel((String) node) >= 3; //at most 4 levels
        		}
        
        		public Object getChild(Object parent, int index) {
        			return parent + "." + index;
        		}
        
        		public int getChildCount(Object parent) {
        			return isLeaf(parent) ? 0 : 2; //each node has 5 children
        		}
        
        		public int getIndexOfChild(Object parent, Object child) {
        			String data = (String) child;
        			int i = data.lastIndexOf('.');
        			return Integer.parseInt(data.substring(i + 1));
        		}
        
        		private int getLevel(String data) {
        			for (int i = -1, level = 0;; ++level)
        				if ((i = data.indexOf('.', i + 1)) < 0)
        					return level;
        		}
        
        	}
        	MyModel myTree = new MyModel();
        ]]></zscript>
        	<vlayout>
        		<tree id="tree" model="${myTree}"
        			onSelect='selectedLabel.setValue(self.getSelectedItem()+", "+self.getSelectedItem().getLabel())'>
        			<template name="model">
        				<treeitem open="false">
        					<treerow>
        						<treecell label="${each}" />
        					</treerow>
        				</treeitem>
        			</template>
        		</tree>
        		<label id="selectedLabel" />
        	</vlayout>
        </zk>
        
        
        
      2. unfold treeitem, click the node "Root.0" and its child nodes.
      3. you'll find whatever level of 1st child nodes you click , selectedLabel always shows the same component uuid and label value as first level node.
      4. The other nodes have the same situation.

            jumperchen jumperchen
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: