当前位置: 代码迷 >> Web前端 >> jquery autocomplete dwr组合 修改Data
  详细解决方案

jquery autocomplete dwr组合 修改Data

热度:448   发布时间:2012-11-09 10:18:48.0
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只能有一次初始化,呵呵 没仔细看例子
  相关解决方案