在使用extjs中treePanel的时候,根节点无法展开子节点,如图所示:
尝试了很多方法都不行,纠结了半天还不知道怎么办?求各位帮帮忙。谢谢。
function alertPanel() {
var btn = new Ext.Button({
text : 'new window'
});
btn.on('click', function() {
var ww = new Ext.Window({
height : 300,
width : 300
});
ww.show();
});
var obj = {
title : "myjs",
width : 700,
height : 600,
maximizable : true,
minimizable : true,
html : 'Hello,easyjf open source',
buttons : [{
text : 'treepanel',
listeners : {
click : function() {
var tree = new Ext.tree.TreePanel({
title : '树的测试',
height : 300,
width : 300,
expanded : true,
root : new Ext.tree.AsyncTreeNode({
text : "根节点",
children : [{
text : "Child 1",
leaf : true
}, {
text : "Child 2",
leaf : true
}]
})
});
var win = new Ext.Window({
title : "简单window窗口",
height : 400,
width : 300,
items : tree
})
win.add(new Ext.Panel({
title : "面板"
}));
win.show(); }
}
}, btn]
};
var win = new Ext.Window(obj);
win.show();
}Ext JSJavaScripttreepaneltreeHTML
尝试了很多方法都不行,纠结了半天还不知道怎么办?求各位帮帮忙。谢谢。
function alertPanel() {
var btn = new Ext.Button({
text : 'new window'
});
btn.on('click', function() {
var ww = new Ext.Window({
height : 300,
width : 300
});
ww.show();
});
var obj = {
title : "myjs",
width : 700,
height : 600,
maximizable : true,
minimizable : true,
html : 'Hello,easyjf open source',
buttons : [{
text : 'treepanel',
listeners : {
click : function() {
var tree = new Ext.tree.TreePanel({
title : '树的测试',
height : 300,
width : 300,
expanded : true,
root : new Ext.tree.AsyncTreeNode({
text : "根节点",
children : [{
text : "Child 1",
leaf : true
}, {
text : "Child 2",
leaf : true
}]
})
});
var win = new Ext.Window({
title : "简单window窗口",
height : 400,
width : 300,
items : tree
})
win.add(new Ext.Panel({
title : "面板"
}));
win.show(); }
}
}, btn]
};
var win = new Ext.Window(obj);
win.show();
}Ext JSJavaScripttreepaneltreeHTML
var btn = new Ext.Button({
text : 'new window'
});
btn.on('click', function() {
var ww = new Ext.Window({
height : 300,
width : 300
});
ww.show();
});
var obj = {
title : "myjs",
width : 700,
height : 600,
maximizable : true,
minimizable : true,
html : 'Hello,easyjf open source',
buttons : [{
text : 'treepanel',
listeners : {
click : function() {
var tree = new Ext.tree.TreePanel({
title : '树的测试',
height : 300,
width : 300,
expanded : true,
root : new Ext.tree.AsyncTreeNode({
text : "根节点",
children : [{
text : "Child 1",
leaf : true
}, {
text : "Child 2",
leaf : true
}]
})
});
var win = new Ext.Window({
title : "简单window窗口",
height : 400,
width : 300,
items : tree
})
win.add(new Ext.Panel({
title : "面板"
}));
win.show(); }
}
}, btn]
};
var win = new Ext.Window(obj);
return win
}Ext.onReady(function(){
var w = alertPanel();
w.show();
})
额(⊙o⊙)… 我复制了你的代码,运行起来还是跟原来一样,无法展开,一直在那边load.....什么情况??
不知道会不会是版本的问题呐?
另外请问下,split这个属性干啥地?API里面查不到的说
看你的JS写法,应该是Extjs3.0+吧,要不你把数据封装成个JS对象试试看.var rootData = [{text : "Child1",leaf:true},{text:"Child2",leaf:true}]
new Ext.tree.AsyncTreeNode({
text : "根节点",
children : rootData
});
function alertPanel() {
var btn = new Ext.Button({
text : 'new window'
});
btn.on('click', function() {
var ww = new Ext.Window({
height : 300,
width : 300
});
ww.show();
});
var obj = {
title : "myjs",
width : 700,
height : 600,
maximizable : true,
minimizable : true,
html : 'Hello,easyjf open source',
buttons : [{
text : 'treepanel',
listeners : {
'click' : function() {
var tree = new Ext.tree.TreePanel({
title : '树的测试',
height : 300,
width : 300,
expanded : true,
root : {
text : "根节点",
children : [{
text : "Child 1",
leaf : true
}, {
text : "Child 2",
leaf : true
}]
}
});
var win = new Ext.Window({
title : "简单window窗口",
height : 400,
width : 300,
items : tree
})
win.add(new Ext.Panel({
title : "面板"
}));
win.show();
}
}
}, btn]
};
var win = new Ext.Window(obj);
return win
};
Ext.onReady(function() {
var w = alertPanel();
w.show();
});
8楼的代码在我这边都无法弹出含有treepanel的那个window了,更别说展开treepanel了,我刚学习ExtJs,还希望能够多多请教你怎么知道我的写法是ExtJs3.0+版本的说?的确,我模仿的视频里面的教程,视频里面用的是3.0+版本的,但是自己用的是2.0版本的。
3.0的tree包下面有TreePanel,不过4.0下面就没有TreePanel只有Panel了,所以4.0想要继承TreePanel,你就得这么写Ext.create('Ext.tree.Panel',{})
怎么回事呢?是不是你的EXT的组件就没有引全呢?
我换成4.0的版本了,然后引用了8楼的代码,可以运行,但是之前不是说4.0版本里面没有TreePanel这个类了吗?那段代码里面使用到了TreePanel类的说。。感觉这个版本的问题,不知道怎么入门了。。
Ext.onReady(simpleTree);
//创造简单的树
function simpleTree() {
var vnode = new Ext.tree.TreeNode({
text : '树根'
});
vnode.appendChild(new Ext.tree.TreeNode({
text : '子节点'
}));
var tree = new Ext.tree.TreePanel({
title : 'simple树',
width : 400,
height : 300,
root : vnode
});
tree.render(document.body);
}
这个代码在4.0环境下,一直报错提示
正如20楼所述:4.0版本里面不包含treepanel类,但是你之前8楼给的代码可以运行的。雾水......
非常谢谢你们的帮忙