jquery autocomplete dwr结合 修改Data
例子: 数据是在别的地方找到的 ^_^
<script type="text/javascript" src="jquery.js"></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript">
var v_1 = [
{ name: "深发展a", id: "000001"},
{ name: "万科a", id: "000002"},
{ name: "st 国 农", id: "000004"},
{ name: "世纪星源", id: "000005"},
{ name: "深振业a", id: "000006"},
{ name: "st 达 声", id: "000007"},
{ name: "st宝利来", id: "000008"},
{ name: "中国宝安", id: "000009"}
];
var v_2 = [
{ name: "s st华新", id: "000010"},
{ name: "山航b", id: "200152"},
{ name: "*st帝贤b", id: "200160"},
{ name: "雷伊b", id: "200168"},
{ name: "宝石b", id: "200413"},
{ name: "小天鹅b", id: "200418"},
{ name: "粤高速b", id: "200429"},
{ name: "宁通信b", id: "200468"},
{ name: "晨鸣b", id: "200488"},
{ name: "珠江b", id: "200505"},
{ name: "闽灿坤b", id: "200512"},
{ name: "华电国际", id: "600027"}
];
jQuery().ready(function() {
jQuery("#stockInfo").autocomplete(
v_1,{
minChars: 1, //最少输入多少字符开始查询
highlight: false,
scroll: true,
scrollHeight: 200,
width: 153, //宽度
matchContains: true,
matchSubset:false,
formatItem: function(row, i, max) {
return i + "/" + max + ": " + row.name ;
},
formatMatch: function(row, i, max) {
return row.name;
}
});
jQuery("#stockInfo").result(function(event, data, formatted) {
//相关的业务处理
alert(data.id);
});
});
//此方法可以被DWR调用来改变Data
function changeToStockInfo(){
$("#stockInfo")
// clear existing data
.val("")
// change the local data to months
.setOptions({data: v_2})
}
</script>
<div id="content">
<form autocomplete="off">
<p>
<input type="button" value="Change Data" onclick="changeToStockInfo();" />
</p>
<p>
<input type="text" id="stockInfo" />
</p>
</form>
</div>
DWR 如何使用这里不介绍了 主要操作就是在回调方法中直接调用changeToStockInfo()来改变Data数据就可以了 之前以为autocomplete只能有一次初始化,呵呵 没仔细看例子