Ticket #5912: tree_custom_nodetype.1.patch
| File tree_custom_nodetype.1.patch, 3.2 kB (added by rcoup, 11 months ago) |
|---|
-
tests/test_Tree.html
20 20 dojo.require("dijit.ColorPalette"); 21 21 dojo.require("dijit.Menu"); 22 22 dojo.require("dojo.parser"); // scan page for widgets and instantiate them 23 24 // Custom TreeNode implementation, useful for overriding templates, 25 // adding checkboxes, or doing other clever things. 26 dojo.declare("MyNodeType", [dijit._TreeNode], { 27 // override something simple & obvious 28 setLabelNode: function(label){ 29 this.labelNode.innerHTML=""; 30 this.labelNode.appendChild(dojo.doc.createTextNode("[MYNODE] " + label)); 31 } 32 }); 23 33 </script> 24 34 25 35 </head> … … 112 122 alert("Execute of node " + this.store.getLabel(item) 113 123 +", population=" + continentStore.getValue(item, "population")); 114 124 </script> 115 </div> 125 </div> 126 127 <h2>A Tree with a custom TreeNode implementation</h2> 116 128 129 <p>Each label should start with "[MYNODE]"</p> 130 <div dojoType="dijit.Tree" id="customNodeTree" 131 store="continentStoreDecorated" labelAttr="name" childrenAttr="children" 132 openOnClick="true" nodeType="MyNodeType"> 133 <script type="dojo/method" event="onClick" args="item"> 134 alert("Execute of node " + continentStore.getLabel(item) 135 +", population=" + continentStore.getValue(item, "population")); 136 </script> 137 </div> 117 138 </body> 118 139 </html> -
Tree.js
175 175 176 176 // Create _TreeNode widget for each specified tree node, unless one already 177 177 // exists and isn't being used (presumably it's from a DnD move and was recently 178 // released 178 // released. We use this.constructor() so that if we're not an actual TreeNode 179 // it continues to work. 179 180 dojo.forEach(items, function(item){ 180 181 var id = store.getIdentity(item), 181 182 existingNode = tree._itemNodeMap[id], 182 183 node = 183 184 ( existingNode && !existingNode.getParent() ) ? 184 185 existingNode : 185 new dijit._TreeNode({186 new this.constructor({ 186 187 item: item, 187 188 tree: this.tree, 188 189 isExpandable: this.tree.mayHaveChildren(item), … … 332 333 onDndCancel:null, 333 334 checkAcceptance:null, 334 335 checkItemAcceptance:null, 335 336 337 // nodeType: Function 338 // constructor function to use for the tree nodes, defaults to dijit._TreeNode 339 nodeType: dijit._TreeNode, 340 336 341 _publish: function(/*String*/ topicName, /*Object*/ message){ 337 342 // summary: 338 343 // Publish a message for this widget/topic … … 358 363 this.connect(this.store, "onDelete", "_onDeleteItem"); 359 364 this.connect(this.store, "onSet", "_onSetItem"); 360 365 } 366 367 // resolve a string nodeType into a function 368 if (dojo.isString(this.nodeType)) { 369 this.nodeType = dojo.getObject(this.nodeType); 370 } 361 371 }, 362 372 363 373 postCreate: function(){ … … 409 419 item = items[0]; 410 420 } 411 421 412 var rn = this.rootNode = new dijit._TreeNode({422 var rn = this.rootNode = new this.nodeType({ 413 423 item: item, 414 424 tree: this, 415 425 isExpandable: true,