首先,先看一个最简单的检索。摘自 http://jqueryui.com/autocomplete/
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
|
|
这个方式只能实现,英文检索英文,中文检索中文。拼音还不能检索中文。
在检索资源不只可以使用对象,也可以使用方法。下面用方法实现拼音检索中文。
source:
function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( platformNames, function( item ){
return matcher.test(Pinyin.GetQP(item).toLowerCase());
}) );
}
});
Pinyin.GetQP(item)是把中文转成拼音的方法。