-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilter_data_plugin.html
More file actions
75 lines (72 loc) · 1.25 KB
/
Copy pathfilter_data_plugin.html
File metadata and controls
75 lines (72 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>test_js_version</title>
<link rel="stylesheet" type="text/css" href="stylesheets/default.css" media="all">
</head>
<body>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
;(function($){
//数据筛选
$.extend({
dataFilter: function(data,keyWord){
if(typeof data == 'object'){
var self = arguments.callee;
return $.map(data,function(val,index){
if(!!~val.name.indexOf(keyWord)){
return val;
}else if(val.child && $.isArray(val.child) && val.child.length){
var val2 = {name:val.name};
val2.child=self(val.child,keyWord);
if(val2.child.length){
return val2;
}
}
});
}else{
return data;
}
}
});
})(jQuery);
$(function(){
//demo
var demoData =[
{
name:'haschild',
child:[
{
name:'child1',
},{
name:'child2',
},{
name:'child3',
},{
name:'child4',
},{
name:'child5',
}
]
},{
name:'meili_top',
child:[]
},{
name:'has_child2',
child:[
{
name:'meili',
},{
name:'nihao',
},{
name:'hello'
}
]
}
];
console.dir($.dataFilter(demoData,'mei'));
});
</script>
</body>
</html>