日期:2014-05-16 浏览次数:20431 次
var tree = Ext.create('Ext.tree.Panel', { title : 'Simple Tree', width : 200, height : 250, queryMode : 'local', id : 'treePanel-id', store : store, rootVisible : false, listeners : { 'itemclick' : function(view, record, items, index, e) { alert(items); if (record.get('leaf') == false) { return; } else { Ext.MessageBox.show({ title : '节点操作', msg : 'itemclick:index=' + index + ",text=" + record.data.text, icon : Ext.MessageBox.INFO }); } }, 'itemcontextmenu' : function(menutree, record, items, index, e) { e.preventDefault(); e.stopEvent(); var obj = record; while (!obj.parentNode.isRoot()) { obj = obj.parentNode; } var rootId = obj.getId(); if (rootId != 180 && rootId != 190) { return; } else { var nodemenu = new Ext.menu.Menu({ floating : true, items : [{ text : "添加文件夹", // icon:'images/add.gif', // iconCls:'leaf', handler : function() { if (record.get('leaf') == false) { Ext.MessageBox.prompt("标题", "請輸入", function(btn, text) { if (btn == "ok") { record.appendChild({ text : text, id : new Date() .getTime(), expanded : true }); } }, this, false, // 表示文本框为多行文本框 "新添加文件夹"); } }, listeners : { render : function(com) { if(record.get('leaf') == true) com.setVisible(false); } } }, { text : "添加子节点", handler : function() { Ext.MessageBox.prompt("标题", "請輸入", function(btn, text) { if (btn == "ok") { record.appendChild({ text : text, id : new Date() .getTime(), expanded : true, leaf : true }); } }, this, false, // 表示文本框为多行文本框 "新添加子节点"); }, listeners : { render : function(com) { if(rootId==190||record.get('leaf') == true) com.setVisible(false); } } }, { text : "编辑", // icon:'images/leaf.gif', // iconCls:'leaf', handler : function() { Ext.MessageBox.prompt("标题", "請輸入", function(btn, text) { if (btn == "ok") { record.data.text= text; } }, this, false, // 表示文本框为多行文本框 record.data.text); } }, { text : "删除", // icon:'images/delete.gif', // iconCls:'leaf', handler : function() { record.remove(record); } }] }); nodemenu.showAt(e.getXY()); } } } });