1/** 2 * [tree æ å½¢ç»ä»¶] 3 * @param {[type]} layid [è¿æ»¤å¨ID] 4 * @param {[type]} data [æ°æ®] 5 * @param {[type]} showCheckbox [å¤éæ¡] 6 * @param {[type]} showLine [è¿æ¥çº¿] 7 * @param {[type]} accordion [æé£ç´æ¨¡å¼] 8 * @param {[type]} onlyIconControl [徿 æ§å¶å±å¼] 9 * @param {[type]} isJump [æ°çªå£è·³è½¬] 10 */ 11layui.use('tree', function () { 12 var $ = layui.$; 13 datatree = function (layid, data, showCheckbox, showLine, accordion, onlyIconControl, isJump) { 14 if (layid) { 15 var _data = data || []; 16 var _showCheckbox = showCheckbox || false; //æ¯å¦æ¾ç¤ºå¤éæ¡ 17 var _showLine = showLine || true; //æ¯å¦å¼å¯è¿æ¥çº¿ãé»è®¤ trueï¼è¥è®¾ä¸º falseï¼åèç¹å·¦ä¾§åºç°ä¸è§å¾æ ã 18 var _accordion = accordion || false; //æ¯å¦å¼å¯æé£ç´æ¨¡å¼ï¼é»è®¤ false 19 var _onlyIconControl = onlyIconControl || false; //æ¯å¦ä» å 许èç¹å·¦ä¾§å¾æ æ§å¶å±å¼æ¶ç¼©ãé»è®¤ false 20 var _isJump = isJump || false; //æ¯å¦å 许ç¹å»èç¹æ¶å¼¹åºæ°çªå£è·³è½¬ãé»è®¤ false 21 var result = { 22 onclick: function () { }, 23 oncheck: function () { }, 24 onspread: function () { }, 25 getChecked: function () { }, 26 setChecked: function () { }, 27 reload: function () { }, 28 getData: function () { // zhangying æ°å¢ getData æ¹æ³ 29 return _data; 30 }, 31 expandNode: function (nodeId) { //zhangying æ°å¢ expandNode æ¹æ³ 32 const tree = layui.tree; 33 const elem = $('#' + layid).find(`[data-id="${nodeId}"]`); 34 if (elem.length > 0) { 35 elem.addClass('layui-tree-spread'); 36 elem.children('.layui-tree-pack').show(); 37 // è°ç¨ spread äºä»¶ 38 result.onspread.call({ state: 'open', data: elem.data() }); 39 } 40 } 41 } 42 43 var tree = layui.tree; 44 var inst1 = tree.render({ 45 elem: '#' + layid, 46 id: layid, //å®ä¹ç´¢å¼ 47 showCheckbox: _showCheckbox, 48 showLine: _showLine, 49 accordion: _accordion, 50 onlyIconControl: _onlyIconControl, 51 isJump: _isJump, 52 data: _data, 53 text: { 54 defaultNodeName: 'æ æ°æ®', 55 none: 'å è½½æ°æ®å¤±è´¥ï¼' 56 }, 57 click: function (obj) { 58 59 result.onclick.call(obj); 60 if (!_showCheckbox) { 61 $('#' + layid).find('.layui-tree-click').removeClass('layui-tree-click'); 62 obj.elem.find('span.layui-tree-txt:first').addClass('layui-tree-click'); 63 } 64 //console.log(obj.data); //å¾å°å½åç¹å»çèç¹æ°æ® 65 // console.log(obj.state); //å¾å°å½åèç¹çå±å¼ç¶æï¼openãcloseãnormal 66 //console.log(obj.elem); //å¾å°å½åèç¹å ç´ 67 // console.log(obj.data.children); //å½åèç¹ä¸æ¯å¦æåèç¹ 68 }, 69 oncheck: function (obj) { 70 result.oncheck.call(obj); 71 //console.log(obj.data); //å¾å°å½åç¹å»çèç¹æ°æ® 72 // console.log(obj.checked); //å¾å°å½åèç¹çå±å¼ç¶æï¼openãcloseãnormal 73 // console.log(obj.elem); //å¾å°å½åèç¹å ç´ 74 }, 75 spread: function (obj) { 76 if (obj.state == 'open') { 77 obj.lazytree = function (data) { 78 tree.lazytree(inst1.config.id, obj.elem, data); 79 } 80 result.onspread.call(obj); 81 } 82 } 83 }); 84 result.getChecked = function () { 85 if (_showCheckbox) { 86 var checkData = tree.getChecked(layid); 87 return checkData; 88 } 89 else { 90 var check = $('#' + layid).find('.layui-tree-click'); 91 if (check.length > 0) { 92 return { id: check.parent().parent().parent().attr('data-id') } 93 } 94 } 95 } 96 result.setChecked = function (data) { 97 if (_showCheckbox) { 98 tree.setChecked(layid, data); 99 } 100 } 101 result.reload = function () { 102 tree.reload(layid, {}); 103 } 104 105 return result; 106 } 107 } 108});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.