标题:autoComplete 还有其他配置项目,以后添加修正
组件会把控件中输入的值,以 固定参数名称添加在source的url后面传递给action。 term=value(value为输入的值)。在后台action中定义一个term变量,即可获取该变量的值
$("#goodsAttributeName_0").autocomplete({
//source有三种形式,function,数值,string(请求数据的地址)
//参数是名是term,自动从控件中获取。
source :"getGoodsAttributeByNameAuto.wss?",
//当光标在一条记录时,可以做的动作,ui.item是所在记录的实体
focus: function(event,ui) {
$("#goodsAttributeName_0").val(ui.item.name);
returnfalse;
},
//当选择一条记录时,可以做的动作,ui.item是所在记录的实体
select: function( event, ui ) {
$("#goodsAttributeName_0").val(ui.item.name);
returnfalse;
}
})
.data("ui-autocomplete")._renderItem =function (ul,item) {
//生成推荐的提示框中的每一列,item是返回的每一条记录,有id,name等值
return $("<li>" )
.append( "<a style='width:378px;'>" +item.name+"</a>" )
.appendTo( ul );
};
public StringgetGoodsAttributeByNameAuto()throws Exception{
//term是页面上控件输入的值,作为参数传入anction中
term =new String(term.getBytes("ISO-8859-1"),"UTF-8");
goodsAttributeList = getAttributeService().getGoodsAttributes(term);
returnSUCCESS;
}
其中参数source是最重要的:
可以有三种输入:
1)数组或者对象(对象的话,对象属性中需要有label和value)
2)string:数据源的地址
3)回调函数。
注意需要:对应的样式和动作的js,css包
jquery-1.7.2.min.js jquery-ui.min.css jquery.autocomplete.js jquery-ui.min.js