直接看代码
1.Java代码(利用的是阿里巴巴的json工具类"import com.alibaba.fastjson.JSON;")
@RequestMapping("getmachineList")
@ResponseBody
public String validateAccount(@RequestParam(value = "storeId") Long storeId){
Map<String,Object> resultMap = new HashMap<String,Object>();
// 体验店机器
SimulatorQueryVo queryVo = new SimulatorQueryVo();
queryVo.setSiteId(storeId);
queryVo.setState(MachineStatusMap.used);
List<Simulator> simulatorList = simulatorService.queryList(queryVo).getModel();
Map<String,Object> map = new HashMap<String,Object>();
for(Simulator simulator:simulatorList)
{
map.put(simulator.getAlias(),simulator.getSerial());
}
resultMap.put("result",map);
String resultAll = JSON.toJSONString(resultMap);
return resultAll;
}
2.jsp页面中解析
//异步获取体验店仿真机
function getmachineList(){
$(".option").remove();
var storeId = $('#query-site').val();
$.ajax({
type: 'POST',
data: 'storeId=' +storeId,
url : '/admin/site/precontract/getmachineList',
dataType: 'json',
success:function(data){
var json = $.parseJSON(data);
var model = json.result;
var i = 0;
$.map(model,function(value,key) {
var alias = key;
var serial = value;
$("#query-machine").append('<option class="option" value="'+serial+'">'+alias+'</option>');
});
},
error:function(){
$.messager.alert("提示","加载失败!","info");
}
});
}