EXT 重写treeLoader
来源:互联网 发布:手机诊断软件 编辑:程序博客网 时间:2024/05/10 16:27
先放在这,有时间再说重写后实现的功能
Ext.ux.bpm.TreeLoader = Ext.extend(Ext.tree.TreeLoader,{
rootId:"0",parseJsonTree:function(mixed,pid){
var childrens = mixed.filterBy(function(item){
if(item['pId']==pid || typeof item['pId'] == 'undefined'){
return true;
}
},this).items;
Ext.each(childrens,function(item,index){
var nodes = this.parseJsonTree(mixed,item.id);
if(nodes && nodes.length){
item.children = nodes;
}
},this);
return childrens;
},
createNode : function(attr){
attr.text = attr.name;
attr.leaf = !(attr.children && attr.children.length);
attr.expanded = attr.open;
return Ext.ux.bpm.TreeLoader.superclass.createNode.call(this,attr);
},
//查找一颗树的根节点
findRootId:function(objs){
var rootId;
for(var i=0;i<objs.length;i++){
var obj = objs[i];
var same = false;
for(var j=0;j<objs.length;j++){
var obj2 = objs[j];
if(obj.pId == obj2.id){
same = true;
break;
}
}
if(same==false){
rootId = obj.pId;
}
}
return rootId;
},
processResponse : function(response, node, callback){
var json = response.responseText;
try {
var o = eval("("+json+")");
var mixed = new Ext.util.MixedCollection(false,function(o){return o.id});
mixed.addAll(o);
this.rootId = this.findRootId(o);
o = this.parseJsonTree(mixed,this.rootId);
node.beginUpdate();
for(var i = 0, len = o.length; i < len; i++){
var n = this.createNode(o[i]);
if(n){
node.appendChild(n);
}
}
node.endUpdate();
if(typeof callback == "function"){
callback(this, node);
}
}catch(e){
this.handleFailure(response);
}
},
initComponent : function(){
Ext.ux.bpm.TreeLoader.superclass.initComponent.apply(this,arguments);
}
});
后台:如果用后果做了树,就不需要这个treeloader
@SuppressWarnings("rawtypes")
private List<Map> pearamsTree(List<Map> roots,Integer rootId){
//过滤出所有的根节点
List<Map> rootsNow = new ArrayList<Map>();
List<Map> otherNodes = new ArrayList<Map>();
for (Map cate : roots) {
if(cate.get("categoryPid")==rootId){
rootsNow.add(cate);
}else{
otherNodes.add(cate);
}
}
for(Map cate :rootsNow){
List<Map> lm = this.pearamsTree(otherNodes,Integer.parseInt(cate.get("id").toString()));
if(lm!=null && lm.size()>0){
cate.put("children", lm);
}else{
cate.put("left", true);
}
}
return rootsNow;
}
下面是使用方式
if (!Global.categoryLoader) {
Global.categoryLoader = new EasyJF.Ext.MemoryTreeLoader({
iconCls : 'lanyo-tree-node-icon',
varName : "Global.DEPT_NODES",
url : "category_getTree?pageSize=-1&treeData=true&all=true",
listeners : {
'beforeload' : function(treeLoader, node) {
treeLoader.baseParams.id = (node.id.indexOf('root') < 0 ? node.id : "");
if (typeof node.attributes.checked !== "undefined") {
treeLoader.baseParams.checked = false;
}
}
}
});
}
{
fieldLabel : '父分类',
name : 'category.categoryPid.id',
xtype : "treecombo",
hiddenName : "category.categoryPid.id",
displayField : "title",
valueField : "id",
tree : new Ext.tree.TreePanel({
autoScroll : true,
rootVisible : false,
root : new Ext.tree.AsyncTreeNode({
id : "root",
text : "部门",
expanded : true,
iconCls : 'treeroot-icon',
loader : Global.categoryLoader
})
}),
listeners : {
scope : this,
select : function(combo, record, index) {
this.operateParentType = record.attributes.type;
}
}
}
- EXT 重写treeLoader
- Ext.tree.TreeLoader异步加载数据
- Ext treeLoader 同步、异步加载树 问题
- Ext treeLoader 同步、异步加载树 问题
- Ext treeLoader 同步、异步加载树 问题
- Ext中TreeLoader加载json数据文件问题
- EXT JS 异步动态树服务端加载 Ext.tree.TreeLoader异步服务端加载
- Ext方法重写
- 重写Ext.form.HtmlEditor
- Ext重写手法
- 重写Ext.Ajax.request,Ext.data.Connection
- treeloader json字符
- Ext1.0重写Ext.form.ComboBox初始化
- 重写Ext.MessageBox.confirm中文按钮名称
- 重写Ext 分页条的传参
- 用Ext.override重写控件属性
- EXT 笔记 构造方法,类继承,类实例方法重写
- 重写EXT treepanel 鼠标移动事件,弹出注释框
- 浅谈教育行业及细分领域的大数据应用
- 2014手游行业关键趋势TOP10
- 微信公众平台开发框架sophia源代码
- 程序员转型书商 年交易额千万元
- BZOJ1087
- EXT 重写treeLoader
- Linux 下用户空间与内核空间数据交换的方式
- code chef - Divide the Tangerine 橘子分块算法题解
- Nandflash 驱动移植
- JavaScript 20140417
- 皇马公布国王杯决赛战巴萨名单
- 13款PHP开发框架
- poj 1113 Wall 凸包
- 板级支持包 BSP