偶尔会遇到jquery操作map的时候,但经常忘记,所以记录一下:
后台java代码,生成Map数据
if (Collections.isNotEmpty(vidList)) {
this.dtcMap = new HashMap<String, Object>();
for (String vid : vidList) {
boolean isExist = (iCache.get("EMC" + vid) != null);
// LOGGER.info("******************************** vid = " + iCache.get("EMC" + vid));
if (isExist) {
dtcMap.put(vid, iCache.get("EMC" + vid));
}
}
}
前台Jquery操作
function getDtcAndGps() {
$.Ajax( {
url : $.webPath + 'obd/monitor/getMonitorRtDtc.do',
success : function(data) {
if (data.errMsg) {
$.alert(data.errMsg);
} else {
$("#carContentDiv").empty();
var html = "";
$.each(data.dtcMap, function(key, value) {
html += "<div id='" + key + "' class='carImg'>A:<img src='" + $.webPath
+ "resources/images/demo/car1.jpg' class='carIcon'/>" + key
+ "</div>";
// html += value;
// html += key;
});
$(html).appendTo("#carContentDiv");
// $.alert(data.dtcMap);
}
}
});
}