开发中往往会遇到需要拼接select,option的情况,作为一个业务前端往往头疼所以整理一下。
controller
@ResponseBody
@RequestMapping("getAccount")
public Map getAccount(
@RequestParam(value = "businessId") String businessId
) {
Map map = new HashMap();
try {
map.put("data", accountInfoService.getByBusinessId(businessId));
} catch (Exception e) {
e.printStackTrace();
map.put("message", "修改失败");
map.put("status", "error");
map.put("icon", "5");
}
return map;
}
前端
function chooseBusiness(t) {
var businessId = $(t).val();
var job= "==请选择==";
if(businessId != ""){
$.ajax({
url: "${ctx}/accountInfo/getAccount?businessId=" + businessId,
type: 'get',
async: false,
success: function (data) {
var list = data.data;
for(var i in list){
job += ""+list[i].clientName+""
}
$("#accountId").html(job);
},
error: function () {
layer.msg("未知错误,请联系管理员!", {icon: 2});
}
});
}
$("#accountId").html(job);
}