最近项目中使用了ligerui组件,需要用到动态下拉树,参照网上的例子,实现了,记录一下,以便以后查找。
版本:
jQuery ligerUI 1.1.9
jQuery v1.7.2
代码如下:
1 $("#region").ligerComboBox({ 2 defaultText:'--请选择--', 3 defaultValue:'', 4 width: 200, 5 selectBoxWidth: 180, 6 selectBoxHeight:150, 7 textField: 'name', 8 valueField:'id', 9 treeLeafOnly:false, 10 tree: { 11 url:'url',//初始化数据 12 textFieldName : 'name', 13 isLeaf:isLeaf,//是否是叶子节点function 14 nodeWidth:250, 15 checkbox: false, 16 btnClickToToggleOnly:true, 17 parentIcon: null, 18 childIcon: null, 19 isExpandCurrent:false,//是否打开当前节点 20 onBeforeSelect:beforeSelect,//选择前事件 function 21 onExpand:onExpand//节点展开事件 function 22 } 23 }); 24 regionTree = $("#region").ligerGetComboBoxManager().treeManager; 25 26 //是否为叶子节点 27 function isLeaf(note){ 28 //自己的判断 29 return boolean; 30 } 31 32 //打开节点 加载数据 33 function onExpand(note){ 34 if (note.data.children == undefined || note.data.children.length == 0) { 35 regionTree.loadData(note.target,'url');//加载子分 36 } 37 } 38 39 //处理选择节点操作 40 function beforeSelect(node){ 41 var id = node.data.id; 42 //赋值或自定义操作 43 return false; 44 }
补充:
异步加载的时候,选项会抖动一下,不知道是什么原因。 希望了解的大牛们指导下。
第一次写博客。希望每一次都有进步~
posted on
浙公网安备 33010602011771号