JS
<link href="<%=request.getContextPath()%>/css/jquery.autocomplete.css" rel="stylesheet" type="text/css">
<script src="<%=request.getContextPath()%>/js/poapply/jquery.autocomplete.js" type="text/javascript" charset="utf-8" ></script>
//解析json数据
function parseFn(data) {
alert(data.jsonData);
var rows = [];
if(data==null)
return rows;
for(var i=0; i<data.length; i++){
rows[rows.length] = {
data:data[i],
result:data[i].PO_NO
};
}
return rows;
}
//自动联想
function getAutoThinkOpts(){
var options={
minChars: 1,
max: 10,
autoFill: false,
mustMatch: false,
matchSubset: false,
matchContains: true,
scrollHeight: 220,
width:200,
matchCase:true,
selectFirst: false,
scroll:false,
dataType: 'json',
parse: parseFn,
formatItem: function(row, i, total) {
return " "+row.PO_NO+" ";
},
formatMatch: function(row, i, total) {
return row.PO_NO;
},
formatResult: function(row) {
return row.PO_NO;
}
};
return options;
}
function initAutoThink(){
var opts = getAutoThinkOpts();
var contractNO = $("#contractNo").val();//$("[name=contractNo]").val();
alert(contractNO)
//$("[name=orderNo]").unautocomplete();
$("#orderNo").unautocomplete();
if(contractNO != ""){
alert(contractNO);
$("#orderNo").autocomplete("/supportmng/pages/usermanage/user/listUserInfo.do?actionFlag=getContractAndSWInfo&contract_no="+contractNO,opts);
}
}
$(document).ready(function(){
initAutoThink();
$("#contractNo").bind("change",initAutoThink);
})
JSP
contractNo:<input type="text" value="" size="20" name="web_doc_id2" id="contractNo">
orderNo:<input type="text" value="" size="20" name="web_doc_id" id="orderNo" autocomplete="off" class="ac_input">
ACTION
public ActionForward getContractAndSWInfo(ActionMapping aMapping,
ActionForm aForm, HttpServletRequest aRequest,
HttpServletResponse aResponse) throws Exception
{
aResponse.setContentType("text/html;charset=UTF-8");
aRequest.setCharacterEncoding("UTF-8");
aResponse.setHeader("Cache-Control", "no-cache");
//合同号
String contractNo = aRequest.getParameter("contract_no");
if (null != contractNo && !"".equals(contractNo))
{
contractNo = contractNo.trim();
}
//订单号
String po_no = aRequest.getParameter("q");
HttpSession session = aRequest.getSession(false);
String nls = (String) session.getAttribute(SupportConstants.CFG_NLS);
JSONObject param = new JSONObject();
param.put("CONTRACT_NO", contractNo);
param.put("PO_NO", po_no);
param.put("LIMIT",10);
param.put("NLS_LANG", nls);
IPoApplyWs poApplyWs = new IPoApplyWsProxy();
String autoDataStr =poApplyWs.getPoNoInfo(param.toString());
JSONArray jsonData = new JSONArray(autoDataStr);
PrintWriter out = aResponse.getWriter();
out.write(jsonData.toString());
// out.flush();
if(null != out){
out.close();
}
return null;
}
<link href="<%=request.getContextPath()%>/css/jquery.autocomplete.css" rel="stylesheet" type="text/css">
<script src="<%=request.getContextPath()%>/js/poapply/jquery.autocomplete.js" type="text/javascript" charset="utf-8" ></script>
//解析json数据
function parseFn(data) {
alert(data.jsonData);
var rows = [];
if(data==null)
return rows;
for(var i=0; i<data.length; i++){
rows[rows.length] = {
data:data[i],
result:data[i].PO_NO
};
}
return rows;
}
//自动联想
function getAutoThinkOpts(){
var options={
minChars: 1,
max: 10,
autoFill: false,
mustMatch: false,
matchSubset: false,
matchContains: true,
scrollHeight: 220,
width:200,
matchCase:true,
selectFirst: false,
scroll:false,
dataType: 'json',
parse: parseFn,
formatItem: function(row, i, total) {
return " "+row.PO_NO+" ";
},
formatMatch: function(row, i, total) {
return row.PO_NO;
},
formatResult: function(row) {
return row.PO_NO;
}
};
return options;
}
function initAutoThink(){
var opts = getAutoThinkOpts();
var contractNO = $("#contractNo").val();//$("[name=contractNo]").val();
alert(contractNO)
//$("[name=orderNo]").unautocomplete();
$("#orderNo").unautocomplete();
if(contractNO != ""){
alert(contractNO);
$("#orderNo").autocomplete("/supportmng/pages/usermanage/user/listUserInfo.do?actionFlag=getContractAndSWInfo&contract_no="+contractNO,opts);
}
}
$(document).ready(function(){
initAutoThink();
$("#contractNo").bind("change",initAutoThink);
})
JSP
contractNo:<input type="text" value="" size="20" name="web_doc_id2" id="contractNo">
orderNo:<input type="text" value="" size="20" name="web_doc_id" id="orderNo" autocomplete="off" class="ac_input">
ACTION
public ActionForward getContractAndSWInfo(ActionMapping aMapping,
ActionForm aForm, HttpServletRequest aRequest,
HttpServletResponse aResponse) throws Exception
{
aResponse.setContentType("text/html;charset=UTF-8");
aRequest.setCharacterEncoding("UTF-8");
aResponse.setHeader("Cache-Control", "no-cache");
//合同号
String contractNo = aRequest.getParameter("contract_no");
if (null != contractNo && !"".equals(contractNo))
{
contractNo = contractNo.trim();
}
//订单号
String po_no = aRequest.getParameter("q");
HttpSession session = aRequest.getSession(false);
String nls = (String) session.getAttribute(SupportConstants.CFG_NLS);
JSONObject param = new JSONObject();
param.put("CONTRACT_NO", contractNo);
param.put("PO_NO", po_no);
param.put("LIMIT",10);
param.put("NLS_LANG", nls);
IPoApplyWs poApplyWs = new IPoApplyWsProxy();
String autoDataStr =poApplyWs.getPoNoInfo(param.toString());
JSONArray jsonData = new JSONArray(autoDataStr);
PrintWriter out = aResponse.getWriter();
out.write(jsonData.toString());
// out.flush();
if(null != out){
out.close();
}
return null;
}