最终要获取的是部门的ID号。方法:
点击下拉框的时候触发事件,使树形目录展开,
点击部门时将获取的值赋给相应的表单项目
//新建用户下拉列表。
var user_combobox = new Ext.form.ComboBox({
store: new Ext.data.SimpleStore({fields:[],data:[[]]}),
id: 'person_combobox',
//hiddenName: 'parent_group',
readOnly: true,
editable:false, //禁止手写及联想功能
fieldLabel: '所属部门',
emptyText: '请选择部门',
blankText: '请选择用户所属部门',
allowBlank: false,
validateOnBlur: true,
mode: 'local',
triggerAction: 'all',
anchor: '90%',
tpl: '<div id="user_group_tree " style="height:200px"></div>',
resizable: true
});
//下拉列表树形结构
var user_tree = new Ext.tree.TreePanel({
border:false,
autoScroll:true,
animate:true,
autoWidth:true,
autoHeight:true,
enableDD:false,
containerScroll: true,
loader: new Ext.tree.TreeLoader({
dataUrl:'tree/modules/combobox.php'
})
});
//树的点击事件
user_tree.on("click",function(node,e)
{
Ext.get('parent_id').dom.value = node.id;//一个隐藏的表单项
user_combobox.setValue(node.text);//设置option值
user_combobox.collapse();//隐藏option列表
});
var user_root = new Ext.tree.AsyncTreeNode({
text: '安一软件公司', //节点名称
draggable:false,
icon:'images/icon/org.gif', //是否支持拖动
id:'asindata' //节点id
});
user_tree.setRootNode(user_root);
//展开option时生成树
user_combobox.on('expand',function(){
user_tree.render('user_group_tree');
user_tree.expandAll();//自动展开树
});
tree/modules/combobox.php产生的结果如下:
[{'id' : '134','text' : '134-right','parent_id' : '1','description' : '111111','str_type' : 'dept','icon'
: 'images/icon/depart.gif','children':[]} ,{'id' : '135','text' : '135-offline','parent_id' : '1','description'
: '111111','str_type' : 'dept','icon' : 'images/icon/depart.gif','children':[]} ,{'id' : '136','text'
: '136','parent_id' : '1','description' : 'asindata','str_type' : 'dept','icon' : 'images/icon/depart
.gif','children':[]} ,{'id' : '138','text' : '138','parent_id' : '1','description' : '','str_type' : 'dept'
,'icon' : 'images/icon/depart.gif','children':[]} ,{'id' : '139','text' : 'asindata','parent_id' : '1'
,'description' : 'asindata','str_type' : 'dept','icon' : 'images/icon/depart.gif','children':[]}
]