1、给下拉框一个id:selectcustomer <select name="mideaOrder.mideaCustomer.id" id="selectcustomer"></select> 2、通过AJax获取后台数据,并在页面加载时候调用
function getSelectCustomer(){ var url="${pageContext.request.contextPath}/manager/mideaCustomer/getALL.action"; $.getJSON(url, function(data) { $.each(data, function(i, item) { $("#selectcustomer").append( "<option value='"+item.value+"'>" + item.text + "</option>"); }); $("#selectcustomer").val('<s:property value="mideaCustomer.id" />'); }); }
3、在后台Action中写getALL()获取后台数据
public void getALL() throws Exception {
MideaCustomer lw = new MideaCustomer();
List<MideaCustomer> list = mideaCustomerDAOImpl.getList(lw);
JSONArray array = new JSONArray();
for (MideaCustomer category : list) {
JSONObject obj = new JSONObject();
obj.put("text", category.getId());
obj.put("value", category.getId());
array.add(obj);
}
this.setResponse(array.toString());
}
jsp页面下拉框绑定数据库中数据
最新推荐文章于 2024-04-22 23:31:26 发布