var arry=[{
id:'ExtJs1',
text:'ExtJs1',
leaf:false,
children:[{
id:'a1',
text:'a1',
leaf:true
},{
id:'b1',
text:'b1',
leaf:true
}]
},{
id:'ExtJs2',
text:'ExtJs2',
leaf:false,
children:[{
id:'a2',
text:'a2',
leaf:true
},{
id:'b2',
text:'b2',
leaf:true
}]
}]
Ext.onReady(function(){
var tree=createTree();
var treeEditor=createTreeEditor(tree);
tree.on('contextmenu',showContextMenu);
tree.render(document.body);
// tree.expandAll();
});
//创建树
function createTree(){
var tree=new Ext.tree.TreePanel({
animate : true,
width :300,
height :300,
enableDD : false,
root : new Ext.tree.TreeNode({
id:'0',
text:'ExtJs',
leaf :false
})
});
createChildTreeNode(tree.root,arry);
return tree;
}
//为某节点创建子节点
function createChildTreeNode(node,childNodes){
for(var i=0;i<childNodes.length;i++){
var childNode=new Ext.tree.TreeNode({
id:childNodes[i].id,
text:childNodes[i].text
});
if(childNodes[i].children!=undefined){
createChildTreeNode(childNode,childNodes[i].children);
}
node.appendChild(childNode);
}
}
//为树创建treeEditor
function createTreeEditor(tree){
var treeEditor=new Ext.tree.TreeEditor(tree,{
allowBlank : false,
blankText : '请输入项目名称',
selectOnFocus : true,
listeners:{'complete':function(){
}}
});
return treeEditor;
}
//创建菜单
function createContextMenu(node,event) {
var contextMenu;
//如果是根节点
if(node.root!=undefined){
contextMenu=new Ext.menu.Menu({
id:'rootMenu',
items:[{
text:'new',
scope:this,
handler:function(){
}
}]
});
return contextMenu;
}
//如果不是叶子节点
else if(node.isLeaf()==false){
contextMenu=new Ext.menu.Menu({
id:'Menu',
items:[{
text:'new',
scope:this,
handler:function(){
}
},'-',{
text:'update',
scope:this,
handler:function(){
}
},'-',{
text:'delete',
scope:this,
handler:function(){
}
}]
});
return contextMenu;
}
//如果是叶子节点
else{
contextMenu=new Ext.menu.Menu({
id:'leafMenu',
items:[{
text:'update',
scope:this,
handler:function(){
}
},'-',{
text:'delete',
scope:this,
handler:function(){
}
}]
});
return contextMenu;
}
}
//显示菜单位置
function showContextMenu(node,event){
var contextMenu=createContextMenu(node,event);
contextMenu.showAt(event.getXY());
}
问题主要是右键菜单达不到预期效果
总是显示else if 那个
[b]问题补充:[/b]
你们说的方法还是不能达到想要的效果
在补充个问题下
怎么让可编辑的grid,编辑完的单元格如果值等于之前的,就没什么变化,如果值不等于之前的就显示出红色