jquery自动完成功能,(边输入边查询)

阅读更多
引入js



jsp代码
	厂商:
	  


js代码:

/****
 * 厂商自动完成功能
 */


$(function() {
	
	$( "#manufacture_temp" ).autocomplete({			
		source: function( request, response ) {
		if(trim(request.term)!=""){
			$.ajax({
				url: "/client/manufactureList.json",
				dataType: "json",
				data: {
					featureClass: "P",
					style: "full",
					maxRows: 12,
					name_startsWith: request.term
				},
				success: function( data ) {
					response( $.map( data.factoryList, function( item ) {
						return {
							label:  item.factoryName,
							value: item.factoryName,
							id:	item.factoryId
						}
					}));
				}
			});
		
		}	
		},
		minLength: 1,
		select: function( event, ui ) {
			document.getElementById("manufactureId").value=ui.item.id ;
			document.getElementById("manufacture").value=ui.item.value ;
			document.getElementById("manufacture_temp").disabled="disabled";
         
		},
		open: function() {
			$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
		},
		close: function() {
			$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
		}
	});
});



后台查询代码:


	/**
	 *模糊查询厂商
	 * 
	 * @param req
	 * @param resp
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("/client/manufactureList.json")
	public ModelAndView manufactureList(HttpServletRequest req,
			HttpServletResponse resp,  ModelMap modelMap) {

		
		String param = req.getParameter("name_startsWith");
		try {
			
			param=	new String(param.getBytes("ISO-8859-1"), "UTF-8").trim();
			
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		List  factoryList= this.clientContractPrfService.queryFactoryList(param);

		modelMap.put("factoryList", factoryList);
		modelMap.put("totalResultsCount", factoryList.size());
		
		return new ModelAndView(jsonView);

	}
}


你可能感兴趣的:(jquery自动完成功能,(边输入边查询))