jquery的autocomplete使用示例

$("#xljhxx_spr_3DE927CE6EE8366E122E3D3A652D5647").autocomplete("/web/commonController.do?getAutoList",
    		{	max: 5,
    			minChars: 1,
    			width: 200,
    			scrollHeight: 100,
    			matchContains: true,
    			autoFill: false,
    			extraParams:	
    				{featureClass : "P",
    				style : "full", 
    				maxRows : 10,
    				labelField : "id,renyuanXm,renyuanDwmc",
    				valueField : "renyuanXm",
    				searchField : "renyuanXm",
    				entityName : "RyEntity",
    				trem: getTremValuexljhxxSpr
    				},
    			parse:function(data){
    				var parsed = [];
	      			$.each(data.rows,function(index,row){
	      				parsed.push({data:row,result:row,value:row.id});
	      			});
					return parsed;
    				//return defineFunc.parse.call(this,data);
    			},
    			formatItem:function(row, i, max){
    				return row.renyuanXm + "-->" + " " + row.renyuanDwmc;
    			} 
    		}).result(function (event, row, formatted) {
    			$("#xljhxx_spr_3DE927CE6EE8366E122E3D3A652D5647").val(row.renyuanXm);
    		}); 
    		function getTremValuexljhxxSpr()
    		{
    			return $("#xljhxx_spr_3DE927CE6EE8366E122E3D3A652D5647").val();
    		}

对应的action方法:

/**
	 * 自动完成请求返回数据
	 * 
	 * @param request
	 * @param responss
	 */
	@RequestMapping(params = "getAutoList")
	public void getAutoList(HttpServletRequest request, HttpServletResponse response, Autocomplete autocomplete) {
		String jsonp = request.getParameter("jsonpcallback");
		String trem = StringUtil.getEncodePra(request.getParameter("trem"));// 重新解析参数
		System.out.println(trem);
		autocomplete.setTrem(trem);
		List autoList = systemService.getAutoList(autocomplete);
		String labelFields = autocomplete.getLabelField();
		String[] fieldArr = labelFields.split(",");
		String valueField = autocomplete.getValueField();
		String[] allFieldArr = null;
		if (StringUtil.isNotEmpty(valueField)) {
			allFieldArr = new String[fieldArr.length+1];
			for (int i=0; i


你可能感兴趣的:(java)