先下一个简单的异步获取选项的操作
<td class="input_content"><input type="text" name="item.odrCustomerName" /> [<span style="cursor:hand;" οnclick="ShowCusMag('dvCus');">选择</span>]</td><!--在单价“选择”的时候触发一个单机事件执行ShowCusMag('dvCus')-->
执行的jquery部分
function ShowCusMag(){ $.get("cusLst.action",reply0,"json");//使用get提交,参数cusLst.action是提交到stauts。xml的路径,参数2是执行完后的数据,参数3,格式是:json ShowDiv('dvCus'); }
//jquery就不详细讲了
function ShowDiv(id){ var oDiv = document.getElementById(id); if (oDiv){ oDiv.style.display = "block"; } }
//执行完AJax后执行的函数 var reply0 = function(data){ if (data != null && typeof data == 'object'){ if (data.length){ var outHtml = "<table>"; for(var i=0;i<data.length;++i){ var cus = data[i]; outHtml += "<tr>"; outHtml += "<td width='180'>" + cus.cusName + "</td>"; outHtml += "<td>[<span style=\"cursor:hand;\" οnclick=\"SelectCus('"+cus.cusId+"','" + cus.cusName + "','" + cus.cusAddr + "');\" >选择</span>]</td>"; outHtml += "</tr>"; } outHtml += "</table>"; var oTable = document.getElementById("tCusList"); oTable.outerHTML = outHtml; } } }
struts.xml配置文件部分
<package name="json" extends="json-default"> <action name="cusLst" class="cn.material.action.CustomerAction" method="list"> <result type="json"> <param name="root">customerList</param> </result> </action> </package>
action部分
public class CustomerAction extends ActionSupport { private List<CusCustomer> customerList; private CustomerService customerService;
//get...和set省略
public String list(){ customerList=this.customerService.getAll();//查询所有 return Action.SUCCESS; }