学习YUI.Ext 第五天--关于树TreePanel(Part 1)
效果演示:http://www.ajaxjs.com/yuicn/demos/order_tree.asp
树组件是YUI.Ext 0.40 新增的组件。虽然YUI已经自带有TREE VIEW的组件,但JACK还是决定重新开发。具体原因在http://www.ajaxjs.com/yuicn/article.asp?id=20070245(翻译文章)或http://www.jackslocum.com/blog/2006/12/29/preview-drag-and-drop-enhancements-and-the-new-treepanel/ (原文)
一、加载一个同步Tree:
复制代码 代码如下:
var TreeTest = function(){
var Tree = YAHOO.ext.tree;// 快捷方式
return {
init : function(){
var tree = new Tree.TreePanel('tree_div', {//需要一个tree_div的holder
animate:true, //是否动画
loader: new Tree.TreeLoader({dataUrl:'get_nodes.asp'}), //调用一个JSON
enableDD:false,// 是否支持拖放
containerScroll: true
});
// 设置根节点
var root = new Tree.AsyncTreeNode({
text: 'Frank的作品', //根节点文字
draggable:false, //根节点是否可拖放
id:'source'
});
tree.setRootNode(root);
// 渲染 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);
通过XHR调用这个get_nodes.asp文件,假设服务器返回这样一个JSON(有关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端JSON的输出(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")+'"},';
rs.MoveNext();
}while(!rs.EOF);
str+="]";
Response.Write(str);
Close();
}
goods= null;
解释:
“text”-->显示的文本
"id"-->id值
“leaf”-->Boolean值,如果“叶子”是真的话,则不能包含子节点Children nodes
"cls"-->选用的样式,通常在这里选定图标
”href“-->指定的url,还有一个”hrefTarget“的属性
另外,除了以上的属性,您还可以在JSON加入任何的属性,作为节点的属性,见Jack原话:
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会继续解释这个问题。
FQA常见问题:
1.Tree支持XML数据交换吗?
A:暂不支持,据FOURM上的话,以后会提供支持,见:
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.我想用单击代替双击展开子节点,可以吗?
A:可以,见:
tree.on('click', function(node){
if(!node.isLeaf()){
node.toggle();
}
});
3.事件处理的几种情形:
A: a.当加入某个节点时,为其增加事件
tree.on('append', function(tree, node){
if(node.id == 'foo'){
// 这里加入你的事件(如click)侦听器(addListener())
}
});b.针对某个节点的单击事件
tree.on('click', function(node){
if(node.id == 'foo'){
// do something
}
});c.针对某个区域(集合)的事件
// fires any time the selection in the tree changes
tree.getSelectionModel().on('selectionchange', function(sm, node){
if(node && node.id == 'foo'){
// do something
}
});
4.如何获取JSON中的自定义字段(或称作参数 parameters)
A:JSON对象已经被构建函数 construction传递到TreeNode中,作为node.attributes 出现,所以调用属性node.attributes 便可获取。详见:http://www.yui-ext.com/forum/viewtopic.php?t=2253
tree.on('click', function(node){
if(!node.isLeaf()){
node.toggle();
}
});
效果演示:http://www.ajaxjs.com/yuicn/demos/order_tree.asp
树组件是YUI.Ext 0.40 新增的组件。虽然YUI已经自带有TREE VIEW的组件,但JACK还是决定重新开发。具体原因在http://www.ajaxjs.com/yuicn/article.asp?id=20070245(翻译文章)或http://www.jackslocum.com/blog/2006/12/29/preview-drag-and-drop-enhancements-and-the-new-treepanel/ (原文)
一、加载一个同步Tree:
复制代码 代码如下:
var TreeTest = function(){
var Tree = YAHOO.ext.tree;// 快捷方式
return {
init : function(){
var tree = new Tree.TreePanel('tree_div', {//需要一个tree_div的holder
animate:true, //是否动画
loader: new Tree.TreeLoader({dataUrl:'get_nodes.asp'}), //调用一个JSON
enableDD:false,// 是否支持拖放
containerScroll: true
});
// 设置根节点
var root = new Tree.AsyncTreeNode({
text: 'Frank的作品', //根节点文字
draggable:false, //根节点是否可拖放
id:'source'
});
tree.setRootNode(root);
// 渲染 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);
通过XHR调用这个get_nodes.asp文件,假设服务器返回这样一个JSON(有关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端JSON的输出(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")+'"},';
rs.MoveNext();
}while(!rs.EOF);
str+="]";
Response.Write(str);
Close();
}
goods= null;
解释:
“text”-->显示的文本
"id"-->id值
“leaf”-->Boolean值,如果“叶子”是真的话,则不能包含子节点Children nodes
"cls"-->选用的样式,通常在这里选定图标
”href“-->指定的url,还有一个”hrefTarget“的属性
另外,除了以上的属性,您还可以在JSON加入任何的属性,作为节点的属性,见Jack原话:
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会继续解释这个问题。
FQA常见问题:
1.Tree支持XML数据交换吗?
A:暂不支持,据FOURM上的话,以后会提供支持,见:
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.我想用单击代替双击展开子节点,可以吗?
A:可以,见:
tree.on('click', function(node){
if(!node.isLeaf()){
node.toggle();
}
});
3.事件处理的几种情形:
A: a.当加入某个节点时,为其增加事件
tree.on('append', function(tree, node){
if(node.id == 'foo'){
// 这里加入你的事件(如click)侦听器(addListener())
}
});b.针对某个节点的单击事件
tree.on('click', function(node){
if(node.id == 'foo'){
// do something
}
});c.针对某个区域(集合)的事件
// fires any time the selection in the tree changes
tree.getSelectionModel().on('selectionchange', function(sm, node){
if(node && node.id == 'foo'){
// do something
}
});
4.如何获取JSON中的自定义字段(或称作参数 parameters)
A:JSON对象已经被构建函数 construction传递到TreeNode中,作为node.attributes 出现,所以调用属性node.attributes 便可获取。详见:http://www.yui-ext.com/forum/viewtopic.php?t=2253
tree.on('click', function(node){
if(!node.isLeaf()){
node.toggle();
}
});
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月27日
2024年11月27日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]