combotree的加载方法

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ComboTree - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="http://www.zi-han.net/case/easyui/jquery-easyui-1.3.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.zi-han.net/case/easyui/jquery-easyui-1.3.1/themes/icon.css">
<link rel="stylesheet" type="text/css" href="http://www.zi-han.net/case/easyui/jquery-easyui-1.3.1/demo/demo.css">
<script type="text/javascript" src="http://www.zi-han.net/case/easyui/jquery-easyui-1.3.1/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="http://www.zi-han.net/case/easyui/jquery-easyui-1.3.1/jquery.easyui.min.js"></script>
<script>

$.fn.tree.defaults.loadFilter = function (data, parent) {
var opt = $(this).data().tree.options;
var idField, textField, parentField;
if (opt.parentField) {
idField = opt.idField || 'id';
textField = opt.textField || 'text';
parentField = opt.parentField;
var i, l, treeData = [], tmpMap = [];
for (i = 0, l = data.length; i < l; i++) {
tmpMap[data[i][idField]] = data[i];
}
for (i = 0, l = data.length; i < l; i++) {
if (tmpMap[data[i][parentField]] && data[i][idField] != data[i][parentField]) {
if (!tmpMap[data[i][parentField]]['children'])
tmpMap[data[i][parentField]]['children'] = [];
data[i]['text'] = data[i][textField];
tmpMap[data[i][parentField]]['children'].push(data[i]);
} else {
data[i]['text'] = data[i][textField];
treeData.push(data[i]);
}
}
return treeData;
}
return data;
};

$.fn.combotree.defaults.loadFilter = $.fn.tree.defaults.loadFilter;
$(function(){
var jsonstr="[{'uid':null,'pageUtil':null,'id':1,'createDate':1415779364000,'modifyDate':1458544814000,'code':'Y001','name':'衣服','sortNo':0,'pid':0,'del':false,'note':'2','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':2,'createDate':1415779377000,'modifyDate':1415779377000,'code':'K001','name':'裤子','sortNo':0,'pid':0,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':3,'createDate':1415779390000,'modifyDate':1465981587000,'code':'Y0011','name':'袜子','sortNo':0,'pid':83,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':4,'createDate':1415779418000,'modifyDate':1420352406000,'code':'Y0022','name':'袄子塔顶','sortNo':0,'pid':83,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':5,'createDate':1415779429000,'modifyDate':1415779429000,'code':'Y0033','name':'运动衣','sortNo':0,'pid':83,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':6,'createDate':1415779455000,'modifyDate':1421036172000,'code':'FADSFDSAFADSFDASFADSFADS','name':'运动鞋FASDFADSFADSFADSFADS','sortNo':0,'pid':0,'del':false,'note':'FADSFADSFADSFADSFADSFDAS','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':7,'createDate':1415779513000,'modifyDate':1415779513000,'code':'ERKE','name':'品牌','sortNo':0,'pid':89,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':97,'createDate':1416411552000,'modifyDate':1419414704000,'code':'KGCZ','name':'开关插座','sortNo':0,'pid':0,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':98,'createDate':1416411574000,'modifyDate':1416411574000,'code':'KGCZ01','name':'86型','sortNo':0,'pid':8,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':99,'createDate':1416411593000,'modifyDate':1419399630000,'code':'KGCZ02','name':'118型','sortNo':0,'pid':8,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':100,'createDate':1416411975000,'modifyDate':1416411975000,'code':'DLQ','name':'断路器','sortNo':0,'pid':0,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':105,'createDate':1419236882000,'modifyDate':1419236882000,'code':'01','name':'电器','sortNo':0,'pid':0,'del':false,'note':'105','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':106,'createDate':1419236940000,'modifyDate':1419236940000,'code':'0101','name':'空调','sortNo':0,'pid':105,'del':false,'note':'106','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':107,'createDate':1419236954000,'modifyDate':1419236954000,'code':'0102','name':'冰箱','sortNo':0,'pid':105,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':110,'createDate':1419237269000,'modifyDate':1419237269000,'code':'0101','name':'手机','sortNo':0,'pid':105,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':111,'createDate':1419237294000,'modifyDate':1419237294000,'code':'010102','name':'触摸屏','sortNo':0,'pid':110,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':112,'createDate':1419237353000,'modifyDate':1419237353000,'code':'01','name':'电器','sortNo':0,'pid':0,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':115,'createDate':1419237560000,'modifyDate':1419402451000,'code':'0123','name':'电器123','sortNo':0,'pid':0,'del':false,'note':'21','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':116,'createDate':1419237574000,'modifyDate':1419237574000,'code':'0101','name':'3c','sortNo':0,'pid':105,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':117,'createDate':1419237585000,'modifyDate':1419237585000,'code':'010101','name':'手机','sortNo':0,'pid':116,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':168,'createDate':1419404597000,'modifyDate':1419404597000,'code':'ASZASZX','name':'ASDSAZX','sortNo':0,'pid':98,'del':false,'note':'XZC','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':176,'createDate':1422414566000,'modifyDate':1422414566000,'code':'1111','name':'111','sortNo':0,'pid':6,'del':false,'note':'11111','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':198,'createDate':1436841555000,'modifyDate':1437446373000,'code':'05000076','name':'猫爪鞋','sortNo':0,'pid':0,'del':false,'note':'丹诗戈','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':203,'createDate':1437533651000,'modifyDate':1437533651000,'code':'11000016','name':'舞蹈鞋','sortNo':0,'pid':0,'del':false,'note':'三沙','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':204,'createDate':1437534200000,'modifyDate':1437534200000,'code':'11000088','name':'足尖鞋','sortNo':0,'pid':0,'del':false,'note':'三沙','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':205,'createDate':1437534813000,'modifyDate':1437534813000,'code':'05000137','name':'连体服','sortNo':0,'pid':0,'del':false,'note':'丹诗戈','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':206,'createDate':1438167068000,'modifyDate':1438582999000,'code':'20','name':'服装','sortNo':0,'pid':1,'del':false,'note':'必迈','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':207,'createDate':1438582798000,'modifyDate':1438582798000,'code':'10','name':'鞋','sortNo':0,'pid':0,'del':false,'note':'必迈','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':208,'createDate':1438583023000,'modifyDate':1438583023000,'code':'30','name':'器配','sortNo':0,'pid':0,'del':false,'note':'必迈','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':209,'createDate':1442805522000,'modifyDate':1442805522000,'code':'11','name':'11','sortNo':0,'pid':5,'del':false,'note':'11','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':210,'createDate':1442807735000,'modifyDate':1442807735000,'code':'ww','name':'ww','sortNo':0,'pid':206,'del':false,'note':'ww','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':211,'createDate':1442975848000,'modifyDate':1442975848000,'code':'02','name':'电视','sortNo':0,'pid':105,'del':false,'note':'02','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':212,'createDate':1442975923000,'modifyDate':1442975923000,'code':'02012','name':'液晶电视','sortNo':0,'pid':211,'del':false,'note':'液晶电视','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':213,'createDate':1442997714000,'modifyDate':1442997816000,'code':'d002','name':'短裤','sortNo':0,'pid':2,'del':false,'note':'ddd','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':214,'createDate':1442997854000,'modifyDate':1442997854000,'code':'m001','name':'毛衣','sortNo':0,'pid':206,'del':false,'note':'mm','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':215,'createDate':1445411610000,'modifyDate':1445411610000,'code':'cj','name':'厨具','sortNo':0,'pid':0,'del':false,'note':'','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':216,'createDate':1445954594000,'modifyDate':1445954594000,'code':'C','name':'上衣','sortNo':0,'pid':0,'del':false,'note':null,'_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':217,'createDate':1445954594000,'modifyDate':1445954594000,'code':'B','name':'短裙','sortNo':0,'pid':0,'del':false,'note':null,'_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':218,'createDate':1467710253000,'modifyDate':1467710253000,'code':'333333333','name':'11111111','sortNo':0,'pid':0,'del':false,'note':'3333333333','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':219,'createDate':1467710909000,'modifyDate':1467710909000,'code':'111','name':'按时发大厦的法定是','sortNo':0,'pid':211,'del':false,'note':'111','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':220,'createDate':1467712667000,'modifyDate':1467712667000,'code':'3333','name':'33333','sortNo':0,'pid':5,'del':false,'note':'3333','_parentId':0,'state':null,'children':null,'parent':false},{'uid':null,'pageUtil':null,'id':221,'createDate':1467712764000,'modifyDate':1467712764000,'code':'11111','name':'111111','sortNo':0,'pid':220,'del':false,'note':'111111','_parentId':0,'state':null,'children':null,'parent':false}]";
var json=eval('(' + jsonstr + ')');
$("#cc").combotree({
idField: 'id',
textField: 'name',
required: false,
parentField: 'pid',
data:json
});


});
</script>
<style>
*{
font-size:12px;
}
body {
font-family:helvetica,tahoma,verdana,sans-serif;
padding:20px;
font-size:13px;
margin:0;
}
h2 {
font-size:18px;
color:#333;
font-weight:bold;
margin:0;
margin-bottom:15px;
}
.demo-info{
background:#FFFEE6;
color:#8F5700;
padding:12px;
}
.demo-tip{
width:24px;
height:16px;
float:left;
}

</style>
</head>
<body>

<input id="cc" name="cc" style="width:200px;">
</body>
</html>

posted @ 2016-09-29 09:30  芜明-追星  阅读(393)  评论(0编辑  收藏  举报