


The sixth day of learning YUI.Ext--About tree TreePanel (Part 1)_YUI.Ext related
The fifth day of learning YUI.Ext - About the tree TreePanel (Part 1)
Effect demonstration: http://www.ajaxjs.com/yuicn/demos/order_tree.asp
The tree component is new in YUI.Ext 0.40 added components. Although YUI already comes with TREE VIEW components, JACK decided to re-develop it. The specific reasons are at http://www.ajaxjs.com/yuicn/article.asp?id=20070245 (translated article) or http://www.jackslocum.com/blog/2006/12/29/preview-drag-and -drop-enhancements-and-the-new-treepanel/ (Original text)
1. Load a synchronized Tree:
var TreeTest = function(){
var Tree = YAHOO.ext.tree;// shortcut
return {
init: function() {
var tree = new Tree.TreePanel('tree_div', {//Need a tree_div holder
animate:true, //whether to animate
loader: new Tree.TreeLoader({dataUrl:'get_nodes .asp'}), //Call a JSON
enableDD:false,//Whether drag and drop is supported
containerScroll: true
});
//Set the root node
var root = new Tree.AsyncTreeNode({
text: 'Frank's work', //Root node text
draggable:false, //Whether the root node can be dragged and dropped
id:'source'
}) ;
tree.setRootNode(root);
// Rendering tree
tree.render(false,false);
// false for not recursive (the default), false to disable animation
root.expand(false,false);
}
};
}();
YAHOO.ext.EventManager.onDocumentReady(TreeTest.init, TreeTest, true);
Call this get_nodes.asp file through XHR, assuming that the server returns such a JSON (introduction to JSON: http://www.json.org/json-zh.html):
[{
"text":"yui-ext.js","id":"/yui-ext.js","leaf":true,"cls":"file"
} ,{
"text ":"yui-ext-1118.php","id":"/yui-ext-1118.php","leaf":true,"cls":"file"
} ,{
" text":"yui-ext-1228.php","id":"/yui-ext-1228.php","leaf":true,"cls":"file"
} ,{
"text":"build","id":"/build","cls":"folder"
} ,{
"text":"source","id":"/source", "cls":"folder"
} ,{
"text":"yui-ext-1123.php","id":"/yui-ext-1123.php","leaf":true ,"cls":"file"
} ,{
"text":"yui-ext-1203.php","id":"/yui-ext-1203.php","leaf": true,"cls":"file"
} ]
Server-side JSON output (ASP JScript)
var goods = new dbOpen();
goods.GetSQL ="select * from goodsbigclass";
with(goods){
GetRS(1);
var str="";
str ="[";
do{
str ='{"text":"' rs("BigClassName") '", "id":"/yui-ext.js","leaf":true,"cls":"file","href":"?b_id=' rs("BigClassID") '"},';
🎜>goods= null;
Explanation:
"text"-->Displayed text
"id"-->id value
"leaf"-->Boolean value, if "leaf" is true , it cannot contain child nodes Children nodes
"cls"-->The selected style, usually the icon selected here
"href"-->the specified url, and there is also a "hrefTarget" attribute
In addition, in addition to the above attributes, you can also add any attribute to JSON as an attribute of the node. See Jack's original words:
The href attribute is called "href", there's also an "hrefTarget" attribute. For capturing node clicks, you can listen on individual nodes or you can listen for "click" on the tree which will pass you the node that was clicked. FYI, you can put any attributes you want in the json config for the node and it will be available as node.attributes. FAQ.4 will continue to explain this issue.
FQA FAQ:
1.Does Tree support XML data exchange?
A: Not supported yet. According to FOURM, support will be provided in the future. See:
can I use xml instead of json for sending nodes hirerachy?
Correct me if I'm wrong but I think the answer is no here. But that doesn't mean it won't be supported later on.
2. I want to use single click instead of double click to expand child nodes. May I?
A: Yes, see:
tree.on('click', function(node){
if(!node.isLeaf()){
node.toggle();
}
});
3. Several situations of event processing:
A: a. When adding a node, add an event to it
tree.on('append', function( tree, node){
if(node.id == 'foo'){
// Add your event (such as click) listener (addListener()) here
}
} );b. Click event for a node
tree.on('click', function(node){
if(node.id == 'foo'){
// do something
}
});c. Events targeting a certain area (collection)
// fires any time the selection in the tree changes
tree.getSelectionModel().on('selectionchange', function(sm, node){
if(node && node.id == 'foo'){
// do something
}
});
4. How to get JSON Custom fields (or parameters)
A: The JSON object has been passed to TreeNode by the construction function construction and appears as node.attributes, so it can be obtained by calling the attribute node.attributes. For details, see: http://www.yui-ext.com/forum/viewtopic.php?t=2253
tree.on('click', function(node){
if(!node.isLeaf( )){
node.toggle();
}
});

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
