博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ExtJS 动态创建

Posted on 2012-07-08 17:48  奥客  阅读(189)  评论(0编辑  收藏  举报

 var root =new Ext.tree.AsyncTreeNode
            ({
                id:
"-100", //根节点id
                text: "xx"
            });

 
var panelmenu =new Ext.Panel({
                width:
200,
                nimSize:
200,
                collapsible:
true,
                collapseMode:
'mini',
               
//                items:extPanel
                //              margins:'0 0 0 5',                  
                layout: 'accordion'
            });
            Ext.Ajax.request({
                url:
'json1.ashx?tree1=1',
                method:
"GET",
                success:
function (response) {
                   
var data = Ext.util.JSON.decode(response.responseText);
                   
for (var i =0; i < data.lenght; i++) {//循环读取 data中的数据来生成panel和tree
                        //                        for (var j = 0; j < data.children.lenght; j++) {
                        //                       
                        //                        }
                        if (data.children.lenght >0) {
                           
// tree.getRootNode().appendChild(data.children);
                            panelmenu.add(new Ext.Panel({
                                id: data[i].id,
                                title: data[i].text,
                                items: [
new Ext.tree.TreePanel({
                                   
//                                renderTo: "show",
                                    autoScroll: true,
                                    containerScroll:
true,
                                    expanded:
false,
                                    root: root,
//定位到根节点
                                    animate: true, //开启动画效果
                                    enableDD: false, //不允许子节点拖动
                                    border: false, //没有边框
                                    //                                layout: 'accordion',
                                    rootVisible: true, //设为false将隐藏根节点
                                    loader: new Ext.tree.TreeLoader({
                                        data: data.children
                                       
//                                                    requestMethod: 'GET'
                                    })
                                   
//                                     tree.render();
                                })]
                            }));
                        }
                       
else {
                            panelmenu.add(
new Ext.Panel({
                                id: data[i].id,
                                title: data[i].text
                            }));
                        }
                    }
                }
            });