提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
|
|
3 |
包依赖: |
|
4 |
/js/jquery-1.11.0.min.js |
|
5 |
/js/cdn/bootstrap3-typeahead.js |
|
6 |
*/ |
|
7 |
/** |
|
8 |
selector:jquery obj, |
|
9 |
|
|
10 |
|
|
11 |
goodstypeahead('#...',function(gs,obj){ |
|
12 |
..... |
|
13 |
}); |
|
14 |
*/ |
|
15 |
var basic=getpath(); |
|
16 |
function goodstypeahead (selector,callback) { |
|
17 |
// body... |
|
18 |
var obj=null; |
|
19 |
if(typeof(selector)=='string') |
|
20 |
obj=$(selector); |
|
21 |
else |
|
22 |
obj=selector; |
|
23 |
obj.typeahead({ |
|
24 |
source:function (query, process) { |
|
25 |
window.goodsstates = [];//=== window.states=[]; |
|
26 |
window.goodsmap = {}; //===window.map={} |
|
27 |
$.ajax({ |
|
28 |
url:basic+'/goods/typehead/gdtypehead.htm', |
|
29 |
type:'post', |
|
30 |
data:{query:query}, |
|
31 |
dataType:'json', |
|
32 |
ansyc:false, |
|
33 |
success:function(json){ |
|
34 |
$.each(json, function (i, item) { |
|
35 |
window.goodsmap[item.name] = item.gs; |
|
36 |
window.goodsstates.push(item.name); |
|
37 |
}); |
|
38 |
process(goodsstates); |
|
39 |
} |
|
40 |
}); |
|
41 |
}, |
|
42 |
updater: function (item) { |
|
43 |
var gs=window.goodsmap[item]; |
|
44 |
callback(gs,obj); |
|
45 |
return gs.name; |
|
46 |
} |
|
47 |
|
|
48 |
}); |
|
49 |
} |