`
smellcode
  • 浏览: 11553 次
  • 性别: Icon_minigender_1
  • 来自: China
最近访客 更多访客>>
社区版块
存档分类
最新评论

基于ext2.0的含有checkBox的tree

    博客分类:
  • Ext
阅读更多
http://www.smellcode.cn/index.php/javascript/jiyuext20dehanyoucheckboxdetree/
分享到:
评论
8 楼 wangangonline 2008-08-09  
ie出不来,firebox可以,但是中为不显示
7 楼 379548695 2008-08-09  
<div class='quote_title'>小蚯蚓 写道</div>
<div class='quote_div'>
<div class='quote_title'>smellcode 写道</div>
<div class='quote_div'>
<div class='quote_title'>引用</div>
<div class='quote_div'>mercuryzhang:看你给的连接,只指出了一个方法。不知道checkboxtree的实现和普通的tree的实现有啥区别,能不能把这个发出来看看啊</div>
你其实可以用最简单的树来实现,不用什么extend<br/>
<pre name='code' class='html'>&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
        &lt;title&gt;Reorder TreePanel&lt;/title&gt;
        &lt;link rel="stylesheet" type="text/css" href="../../../support/resources/css/ext-all.css" /&gt;

        &lt;script type="text/javascript" src="../../../support/adapter/ext/ext-base.js"&gt;&lt;/script&gt;

        &lt;script type="text/javascript" src="../../../support/js/ext-all-debug.js"&gt;&lt;/script&gt;

        &lt;script type="text/javascript"&gt;
            Ext.BLANK_IMAGE_URL = "../../../support/resources/images/default/s.gif"
            var tree = null;
            Ext.onReady(function(){
                // shorthand
                var Tree = Ext.tree;
               
                tree = new Tree.TreePanel({
                    el:'tree-div',
                    autoScroll:true,
                    animate:true,
                    enableDD:true,
                    containerScroll: true,
                    loader: new Tree.TreeLoader({
                        dataUrl:'xmmapjson.json'
                    }),
                    rootVisible: false
                });

               
                tree.on('checkchange', function(node, checked) {
                    node.expand();
                    node.attributes.checked = checked;
                    node.eachChild(function(child) {
                        child.ui.toggleCheck(checked);
                        child.attributes.checked = checked;
                        child.fireEvent('checkchange', child, checked);
                    });
                }, tree);

                // set the root node
                var root = new Tree.AsyncTreeNode({
                    text: 'root',
                    draggable:false,
                    id:'root'
                });

                tree.setRootNode(root);

                // render the tree
                tree.render();
                root.expand();
            });


            var fn = function() {
                alert(tree.getChecked('id'));
            };

    &lt;/script&gt;
    &lt;/head&gt;
    &lt;body scroll="no"&gt;
        &lt;b&gt;Checked Nodes: &lt;/b&gt; &lt;input type="text" id="cn" value="" size="40" autocomplete="off" /&gt;&lt;br /&gt;
        &lt;div id="tree-div" style="overflow:auto; height:300px;width:300px;border:1px solid #c3daf9;"&gt;&lt;/div&gt;
        &lt;input type="button" id="gacv" value="getAllCheckedValue" onclick="fn()" /&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p> 这是json数组:</p>
<pre name='code' class='xml'>[
{"text":"请选择","id":"all1","leaf":false,"checked":false,"depth":"0",
"children":[
{"text":"资产价值","id":"zichanjiazhi","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"100万以下","id":"100yixia","leaf":true,"checked":false,"depth":"2"},
{"text":"100万-500万","id":"100zhi500","leaf":true,"checked":false,"depth":"2"},
{"text":"500万-1000万","id":"500zhi1000","leaf":true,"checked":false,"depth":"2"},
{"text":"1000万以上","id":"1000yishang","leaf":true,"checked":false,"depth":"2"}
]
},
{"text":"资产类型","id":"zichanleixing","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"生产类","id":"shengchanlei","leaf":false,"checked":false,"depth":"2",
"children":[
{"text":"土地类","id":"tudilei","leaf":true,"checked":false,"depth":"3"},
{"text":"设备类","id":"shebeilei","leaf":true,"checked":false,"depth":"3"},
{"text":"建筑类","id":"jianzhulei","leaf":true,"checked":false,"depth":"3"}
]
},
{"text":"非生产类","id":"feishengchanlei","leaf":false,"checked":false,"depth":"2",
"children":[
{"text":"土地类","id":"feitudilei","leaf":true,"checked":false,"depth":"3"},
{"text":"设备类","id":"feishebeilei","leaf":true,"checked":false,"depth":"3"},
{"text":"建筑类","id":"feijianzhulei","leaf":true,"checked":false,"depth":"3"}
]
}
]
},
{"text":"单位类型","id":"danweileixing","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"工业","id":"gongye","leaf":true,"checked":false,"depth":"2"},
{"text":"商业","id":"shangye","leaf":true,"checked":false,"depth":"2"},
{"text":"直属企业","id":"zhisuqiye","leaf":true,"checked":false,"depth":"2"}
]
},
{"text":"使用状态","id":"shiyongzhuangtai","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"在建","id":"zaijian","leaf":true,"checked":false,"depth":"2"},
{"text":"在用","id":"zaiyong","leaf":true,"checked":false,"depth":"2"},
{"text":"租出","id":"zuchu","leaf":true,"checked":false,"depth":"2"},
{"text":"调拨","id":"diaobo","leaf":true,"checked":false,"depth":"2"},
{"text":"闲置","id":"xianzhi","leaf":true,"checked":false,"depth":"2"},
{"text":"报废","id":"baofei","leaf":true,"checked":false,"depth":"2"}
]
},
{"text":"资产来源","id":"zichanlaiyuan","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"购买","id":"gongmai","leaf":true,"checked":false,"depth":"2"},
{"text":"项目","id":"xiangmu","leaf":true,"checked":false,"depth":"2"},
{"text":"融资","id":"rongzhi","leaf":true,"checked":false,"depth":"2"},
{"text":"租入","id":"zuru","leaf":true,"checked":false,"depth":"2"}
]
}
]
}
]
</pre>
 
<p> </p>
<p> </p>
</div>
</div>
<div class='quote_div'><br/>但是发现一个问题就是,当你将节点收拢的后,再展开节点,节点下的构选项无法保存,也就是说,child.ui.toggleCheck(checked);根本没有保存变化,我用的版本是2.0b</div>
<div class='quote_div'><br/></div>
<div class='quote_div'><br/></div>
<div class='quote_div'>你把<span>animate:false,  看看。就可以啦!<br/></span></div>
6 楼 aiwobucuo 2008-06-28  
你的JSON数据组是怎么样生成的啊
5 楼 c_mingze@163.com 2008-06-15  
我也写了一个复选框的树
但是我想 知道怎么实现、特定情况下把页面变成灰色 就是不可以对chenked  或是当前这棵树进行操作。
4 楼 小蚯蚓 2008-03-19  
<div class='quote_title'>smellcode 写道</div><div class='quote_div'><div class='quote_title'>引用</div><div class='quote_div'>mercuryzhang:看你给的连接,只指出了一个方法。不知道checkboxtree的实现和普通的tree的实现有啥区别,能不能把这个发出来看看啊</div>你其实可以用最简单的树来实现,不用什么extend<br/><pre name='code' class='html'>&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
        &lt;title&gt;Reorder TreePanel&lt;/title&gt;
        &lt;link rel="stylesheet" type="text/css" href="../../../support/resources/css/ext-all.css" /&gt;

        &lt;script type="text/javascript" src="../../../support/adapter/ext/ext-base.js"&gt;&lt;/script&gt;

        &lt;script type="text/javascript" src="../../../support/js/ext-all-debug.js"&gt;&lt;/script&gt;

        &lt;script type="text/javascript"&gt;
            Ext.BLANK_IMAGE_URL = "../../../support/resources/images/default/s.gif"
            var tree = null;
            Ext.onReady(function(){
                // shorthand
                var Tree = Ext.tree;
               
                tree = new Tree.TreePanel({
                    el:'tree-div',
                    autoScroll:true,
                    animate:true,
                    enableDD:true,
                    containerScroll: true,
                    loader: new Tree.TreeLoader({
                        dataUrl:'xmmapjson.json'
                    }),
                    rootVisible: false
                });

               
                tree.on('checkchange', function(node, checked) {
                    node.expand();
                    node.attributes.checked = checked;
                    node.eachChild(function(child) {
                        child.ui.toggleCheck(checked);
                        child.attributes.checked = checked;
                        child.fireEvent('checkchange', child, checked);
                    });
                }, tree);

                // set the root node
                var root = new Tree.AsyncTreeNode({
                    text: 'root',
                    draggable:false,
                    id:'root'
                });

                tree.setRootNode(root);

                // render the tree
                tree.render();
                root.expand();
            });


            var fn = function() {
                alert(tree.getChecked('id'));
            };

    &lt;/script&gt;
    &lt;/head&gt;
    &lt;body scroll="no"&gt;
        &lt;b&gt;Checked Nodes: &lt;/b&gt; &lt;input type="text" id="cn" value="" size="40" autocomplete="off" /&gt;&lt;br /&gt;
        &lt;div id="tree-div" style="overflow:auto; height:300px;width:300px;border:1px solid #c3daf9;"&gt;&lt;/div&gt;
        &lt;input type="button" id="gacv" value="getAllCheckedValue" onclick="fn()" /&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre><p> 这是json数组:</p><pre name='code' class='xml'>[
{"text":"请选择","id":"all1","leaf":false,"checked":false,"depth":"0",
"children":[
{"text":"资产价值","id":"zichanjiazhi","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"100万以下","id":"100yixia","leaf":true,"checked":false,"depth":"2"},
{"text":"100万-500万","id":"100zhi500","leaf":true,"checked":false,"depth":"2"},
{"text":"500万-1000万","id":"500zhi1000","leaf":true,"checked":false,"depth":"2"},
{"text":"1000万以上","id":"1000yishang","leaf":true,"checked":false,"depth":"2"}
]
},
{"text":"资产类型","id":"zichanleixing","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"生产类","id":"shengchanlei","leaf":false,"checked":false,"depth":"2",
"children":[
{"text":"土地类","id":"tudilei","leaf":true,"checked":false,"depth":"3"},
{"text":"设备类","id":"shebeilei","leaf":true,"checked":false,"depth":"3"},
{"text":"建筑类","id":"jianzhulei","leaf":true,"checked":false,"depth":"3"}
]
},
{"text":"非生产类","id":"feishengchanlei","leaf":false,"checked":false,"depth":"2",
"children":[
{"text":"土地类","id":"feitudilei","leaf":true,"checked":false,"depth":"3"},
{"text":"设备类","id":"feishebeilei","leaf":true,"checked":false,"depth":"3"},
{"text":"建筑类","id":"feijianzhulei","leaf":true,"checked":false,"depth":"3"}
]
}
]
},
{"text":"单位类型","id":"danweileixing","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"工业","id":"gongye","leaf":true,"checked":false,"depth":"2"},
{"text":"商业","id":"shangye","leaf":true,"checked":false,"depth":"2"},
{"text":"直属企业","id":"zhisuqiye","leaf":true,"checked":false,"depth":"2"}
]
},
{"text":"使用状态","id":"shiyongzhuangtai","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"在建","id":"zaijian","leaf":true,"checked":false,"depth":"2"},
{"text":"在用","id":"zaiyong","leaf":true,"checked":false,"depth":"2"},
{"text":"租出","id":"zuchu","leaf":true,"checked":false,"depth":"2"},
{"text":"调拨","id":"diaobo","leaf":true,"checked":false,"depth":"2"},
{"text":"闲置","id":"xianzhi","leaf":true,"checked":false,"depth":"2"},
{"text":"报废","id":"baofei","leaf":true,"checked":false,"depth":"2"}
]
},
{"text":"资产来源","id":"zichanlaiyuan","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"购买","id":"gongmai","leaf":true,"checked":false,"depth":"2"},
{"text":"项目","id":"xiangmu","leaf":true,"checked":false,"depth":"2"},
{"text":"融资","id":"rongzhi","leaf":true,"checked":false,"depth":"2"},
{"text":"租入","id":"zuru","leaf":true,"checked":false,"depth":"2"}
]
}
]
}
]
</pre> <p> </p><p> </p></div><br/>但是发现一个问题就是,当你将节点收拢的后,再展开节点,节点下的构选项无法保存,也就是说,child.ui.toggleCheck(checked);根本没有保存变化,我用的版本是2.0b
3 楼 smellcode 2008-02-23  
<div class='quote_title'>引用</div><div class='quote_div'>mercuryzhang:看你给的连接,只指出了一个方法。不知道checkboxtree的实现和普通的tree的实现有啥区别,能不能把这个发出来看看啊</div>你其实可以用最简单的树来实现,不用什么extend<br/><pre name='code' class='html'>&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
        &lt;title&gt;Reorder TreePanel&lt;/title&gt;
        &lt;link rel="stylesheet" type="text/css" href="../../../support/resources/css/ext-all.css" /&gt;

        &lt;script type="text/javascript" src="../../../support/adapter/ext/ext-base.js"&gt;&lt;/script&gt;

        &lt;script type="text/javascript" src="../../../support/js/ext-all-debug.js"&gt;&lt;/script&gt;

        &lt;script type="text/javascript"&gt;
            Ext.BLANK_IMAGE_URL = "../../../support/resources/images/default/s.gif"
            var tree = null;
            Ext.onReady(function(){
                // shorthand
                var Tree = Ext.tree;
               
                tree = new Tree.TreePanel({
                    el:'tree-div',
                    autoScroll:true,
                    animate:true,
                    enableDD:true,
                    containerScroll: true,
                    loader: new Tree.TreeLoader({
                        dataUrl:'xmmapjson.json'
                    }),
                    rootVisible: false
                });

               
                tree.on('checkchange', function(node, checked) {
                    node.expand();
                    node.attributes.checked = checked;
                    node.eachChild(function(child) {
                        child.ui.toggleCheck(checked);
                        child.attributes.checked = checked;
                        child.fireEvent('checkchange', child, checked);
                    });
                }, tree);

                // set the root node
                var root = new Tree.AsyncTreeNode({
                    text: 'root',
                    draggable:false,
                    id:'root'
                });

                tree.setRootNode(root);

                // render the tree
                tree.render();
                root.expand();
            });


            var fn = function() {
                alert(tree.getChecked('id'));
            };

    &lt;/script&gt;
    &lt;/head&gt;
    &lt;body scroll="no"&gt;
        &lt;b&gt;Checked Nodes: &lt;/b&gt; &lt;input type="text" id="cn" value="" size="40" autocomplete="off" /&gt;&lt;br /&gt;
        &lt;div id="tree-div" style="overflow:auto; height:300px;width:300px;border:1px solid #c3daf9;"&gt;&lt;/div&gt;
        &lt;input type="button" id="gacv" value="getAllCheckedValue" onclick="fn()" /&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre><p> 这是json数组:</p><pre name='code' class='xml'>[
{"text":"请选择","id":"all1","leaf":false,"checked":false,"depth":"0",
"children":[
{"text":"资产价值","id":"zichanjiazhi","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"100万以下","id":"100yixia","leaf":true,"checked":false,"depth":"2"},
{"text":"100万-500万","id":"100zhi500","leaf":true,"checked":false,"depth":"2"},
{"text":"500万-1000万","id":"500zhi1000","leaf":true,"checked":false,"depth":"2"},
{"text":"1000万以上","id":"1000yishang","leaf":true,"checked":false,"depth":"2"}
]
},
{"text":"资产类型","id":"zichanleixing","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"生产类","id":"shengchanlei","leaf":false,"checked":false,"depth":"2",
"children":[
{"text":"土地类","id":"tudilei","leaf":true,"checked":false,"depth":"3"},
{"text":"设备类","id":"shebeilei","leaf":true,"checked":false,"depth":"3"},
{"text":"建筑类","id":"jianzhulei","leaf":true,"checked":false,"depth":"3"}
]
},
{"text":"非生产类","id":"feishengchanlei","leaf":false,"checked":false,"depth":"2",
"children":[
{"text":"土地类","id":"feitudilei","leaf":true,"checked":false,"depth":"3"},
{"text":"设备类","id":"feishebeilei","leaf":true,"checked":false,"depth":"3"},
{"text":"建筑类","id":"feijianzhulei","leaf":true,"checked":false,"depth":"3"}
]
}
]
},
{"text":"单位类型","id":"danweileixing","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"工业","id":"gongye","leaf":true,"checked":false,"depth":"2"},
{"text":"商业","id":"shangye","leaf":true,"checked":false,"depth":"2"},
{"text":"直属企业","id":"zhisuqiye","leaf":true,"checked":false,"depth":"2"}
]
},
{"text":"使用状态","id":"shiyongzhuangtai","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"在建","id":"zaijian","leaf":true,"checked":false,"depth":"2"},
{"text":"在用","id":"zaiyong","leaf":true,"checked":false,"depth":"2"},
{"text":"租出","id":"zuchu","leaf":true,"checked":false,"depth":"2"},
{"text":"调拨","id":"diaobo","leaf":true,"checked":false,"depth":"2"},
{"text":"闲置","id":"xianzhi","leaf":true,"checked":false,"depth":"2"},
{"text":"报废","id":"baofei","leaf":true,"checked":false,"depth":"2"}
]
},
{"text":"资产来源","id":"zichanlaiyuan","leaf":false,"checked":false,"depth":"1",
"children":[
{"text":"购买","id":"gongmai","leaf":true,"checked":false,"depth":"2"},
{"text":"项目","id":"xiangmu","leaf":true,"checked":false,"depth":"2"},
{"text":"融资","id":"rongzhi","leaf":true,"checked":false,"depth":"2"},
{"text":"租入","id":"zuru","leaf":true,"checked":false,"depth":"2"}
]
}
]
}
]
</pre> <p> </p><p> </p>
2 楼 mercuryzhang 2008-02-22  
看不懂啊,能不能把整个tree地实现给出来啊。谢谢
1 楼 kaki 2008-02-20  
node.eachChild(function(child) {
		child.ui.toggleCheck(checked);
		child.attributes.checked = checked;
		child.fireEvent('checkchange', child, checked);
	});



感谢分享,这一句很关键!

相关推荐

    EXT2.0中文教程

    9.2. 带全选的checkbox树形CheckBoxTree 9.3. 带全选的checkbox的grid 9.4. fisheye 9.5. 可以设置时间的日期控件 9.6. JsonView实现用户卡片拖拽与右键菜单 9.7. 下拉列表选择每页显示多少数据 10. 撕裂吧!...

    Ext js-2.0 带API

     自动生成行号,支持checkbox全选,动态选择显示哪些列,支持本地以及远程分页,可以对单元格按照自己的想法进行渲染,这些也算可以想到的功能。  再加上可编辑grid,添加新行,删除一或多行,提示脏数据,推拽...

    EXT教程EXT用大量的实例演示Ext实例

    例如,TreeField和CheckBoxTree等控件都是扩展自标准组件的功能。此外,Ext JS还可以与其他技术(如dwr、localXHR等)整合,增加更多的功能和灵活性。 #### 9. 常见问题解答 在Ext使用过程中,可能遇到各种问题,...

    Ext 开发指南 学习资料

    9.2. 带全选的checkbox树形CheckBoxTree 9.3. 带全选的checkbox的grid 9.4. fisheye 9.5. 可以设置时间的日期控件 9.6. JsonView实现用户卡片拖拽与右键菜单 9.7. 下拉列表选择每页显示多少数据 10. 撕裂吧!...

    掏钱学Ext(完整版) 附全部源码

    9.2. 带全选的checkbox树形CheckBoxTree 9.3. 带全选的checkbox的grid A. 常见问题乱弹 A.1. 怎么查看ext2里的api文档 A.2. 想把弹出对话框单独拿出来用的看这里 A.3. 想把日期选择框单独拿出来用的看这里 ...

    深入浅出Ext JS

     呵呵~不过ext也不是万能的,与fins的ecside比较,ext不能锁定列(土豆说1.x里支持锁定列,但是2.0里没有了,因为影响效率。),也没有默认的统计功能,也不支持excel,pdf等导出数据。另外fins说,通过测试ecside...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    注:ExtAspNet基于一些开源的程序ExtJS, HtmlAgilityPack, Nii.JSON, YUICompressor。 示例: http://extasp.net/ 开源: http://extaspnet.codeplex.com/ 博客: http://sanshi.cnblogs.com/ 邮箱: sanshi.ustc@gmail...

    EXTJS开发文档

    自动生成行号,支持checkbox全选,动态选择显示哪些列,支持本地以及远程分页,可以对单元格按照自己的想法进行渲染,这些也算可以想到的功能。 再加上可编辑grid,添加新行,删除一或多行,提示多行数据,拖拽改变...

    很不错的ExtJs PPT

    EXTJS是一种基于JavaScript的UI框架,它源自JAVASCRIPT,致力于提供丰富的Web2.0用户体验。EXTJS的核心特点是利用CSS来控制DIV元素,从而创建出具有高度交互性和良好视觉效果的网页应用。EXTJS充分利用AJAX技术,...

    ExtAspNet_v2.3.2_dll

    支持的浏览器: IE 7.0+, Firefox 3.0+, Chrome 2.0+, Opera 9.5+, Safari 3.0+ 注:ExtAspNet基于一些开源的程序ExtJS, HtmlAgilityPack, Nii.JSON, YUICompressor。 示例: http://extasp.net/ 开源: ...

Global site tag (gtag.js) - Google Analytics