ExtJs3.3 TreePanel,checked节点和平常节点同时存在

 

参考官方的例子做的。想要tree的节点是checkbox的。只需要在返回的json的数据里面,"checked":false 即可,这里注意false是不加引号的。其他节点是平常节点只要不返回这个checked节点即可!

[{"text":"企业","id":"EntAllID","cls":"folder","checked":false},{"text":"污水处理厂","id":"SewAllID","leaf":"true","checked":false},
{"text":"河流断面","id":"SectionID","leaf":"true","checked":false},{"text":"引用水
源地","id":"DrinkSourceID","leaf":"true","checked":false},
{"text":"闸坝","id":"WatDamID","leaf":"true","checked"
:false},{"text":"应急组织队伍","id":"EmergencyTeamID","leaf":"true","checked":false},
{"text":"物资库","id":"EmeSocialResourceID1"
,"leaf":"true","checked":false},{"text":"外协队伍","id":"OutTeamsID","leaf":"true","checked":false}]
 var Tree = Ext.tree;
        var tree = new Tree.TreePanel({
            height: 350,
            //width: 150,
            region: 'north',
            autoScroll: true,
            border: false,
            bodyBorder: false,
            lines: true,
            split: true,
            minSize: 110,
            maxSize: 400,
            useArrows: true,
            //autoScroll: true,
            animate: true,
            //enableDD: true,
            containerScroll: true,
            border: false,
            // auto create TreeLoader
            dataUrl: 'web/ashx/tree.aspx',

            root: {
                nodeType: 'async',
                text: '数据中心',
                draggable: false,
                id: 'all'
            }
        });
        //要实现我们想要的选中父节点的checkbox后,自动选中子节点也很简单,只需要加上下面这一段代码就可以了。
        tree.on('checkchange', function (node, checked) {
            var id = node.id;
            var text = node.text;

            node.expand(); //展开改节点
            node.attributes.checked = checked; //当前节点的选中状态
            var lay = top.getLayerById(id)//top
            if (lay) {
                lay.an_visible = checked;
            }
            else {
                if (checked) {
                    InitCreatLayer(id);
                }
            }
            if (node.hasChildNodes()) {
                //循环当前节点的子节点
                node.eachChild(function (child) {
                    child.ui.toggleCheck(checked);
                    child.attributes.checked = checked;
                    child.fireEvent('checkchange', child, checked);
                    
                    
                });
            }

        }, tree);
        //树的点击事件
        tree.on("click", function(node, e) {
            //alert("点击的节点ID是:" + node.id + ",文字是:" +node.text);
            //当是根节点的时候
            if (node.leaf) {
                var parentnode = node.parentNode.id;//获取当前节点的父节点
                if (parentnode == "-2") {
                    top.FlyToPointByType('T0139_EntModel', node.id);
                }
                else if (parentnode == "-3") {
                    top.FlyToPointByType('T0216_BiaoZhi', node.id);
                }
                else if (parentnode == "-4") {

                }
            }
        });

        tree.getRootNode().expand();//默认根节点展开

根据ID查找节点,并展开这个节点:

 tree.getNodeById('id').expand();

//下面的方法没有成功,不知道这样写对不对

 var path = forumTree.getNodeById('id').getPath(); alert(path);
 tree.expandPath(path);

//展开路径,并在回调函数里面选择该节点

var path="/id1/id2"
tree.expandPath(path, 'id', function(bSucess, oLastNode) {
  alert(bSucess);
  //forumTree.getSelectionModel().select(oLastNode); //选择该节点
});

posted @ 2012-08-13 15:04  高山-景行  阅读(681)  评论(0编辑  收藏  举报