Skip to content

Instantly share code, notes, and snippets.

@x03570227
Created June 26, 2012 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x03570227/2994798 to your computer and use it in GitHub Desktop.
Save x03570227/2994798 to your computer and use it in GitHub Desktop.
Extjs4 树写法
Ext.define("ast.ast1949.util.TreeSelectorWin",{
extend:"Ext.Window",
initComponent:function(){
var tree=Ext.create("ast.ast1949.util.Tree",{
rootCode:this.getRootCode(),
treeModel:this.getTreeModel(),
queryUrl:this.getQueryUrl(),
rootexpanded:false
});
var c={
layout:"fit",
items:[tree],
buttons:[{
text:"选择",
iconCls:"accept16",
scope:this,
handler:function(btn,e){
//tree选中项
var model=tree.getSelectionModel().getLastSelected();
this.callbackFn(model);
}
},{
text:"关闭",
iconCls:"close16",
scope:this,
handler:function(btn,e){
this.close();
}
}]
};
Ext.applyIf(this,c);
this.callParent();
},
rootCode:"",
treeModel:"CategoryTreeModel",
queryUrl:Context.ROOT+"/path/to/tree/node.htm",
config:{
queryUrl:null,
rootCode:null,
initCode:null,
treeModel:"CategoryTreeModel"
},
callbackFn:function(nodeInterface){
},
initTree:function(codelength){
var path="/";
codelength=codelength||4;
var pathArr=new Array();
if(this.getInitCode()!=null && this.getInitCode().length>0){
for(var i=this.getRootCode().length;i<=this.getInitCode().length;i=i+codelength){
pathArr.push(this.getInitCode().substring(0,i));
}
}
if(pathArr.length>0){
path=path+pathArr.join("/");
this.child("treepanel").selectPath(path, "id");
}else{
path=path+this.getRootCode();
// this.child("treepanel").expandPath(path, "id");
this.child("treepanel").getRootNode().expand();
}
}
});
Ext.define("CategoryTreeModel",{
extend: 'Ext.data.Model',
fields:[{name:"id",mapping:"data"},{name:"text",mapping:"text"},{name:"leaf",mapping:"leaf"}]
});
Ext.define("ast.ast1949.util.Tree",{
extend:"Ext.tree.Panel",
initComponent:function(){
var store=Ext.create("Ext.data.TreeStore",{
nodeParam:"parentCode",
defaultRootId:this.getRootCode(),
model:this.getTreeModel(),
proxy:{
type:"ajax",
url:this.getQueryUrl(),
reader: {
type: 'json',
root: 'records'
}
},
root:{
expanded:this.getRootexpanded(),
text:'所有类别'
}
});
var c={
store: store
}
Ext.applyIf(this,c);
this.callParent();
},
rootCode:"",
treeModel:"CategoryTreeModel",
queryUrl:Context.ROOT+"/path/to/tree/node.htm",
rootexpanded:false,
config:{
queryUrl:null,
rootCode:null,
treeModel:"CategoryTreeModel",
rootexpanded:false
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment