ajax返回map的值,同时在sucess返回时的显示

代码:
EventVo eventVo = eventService.eventDetail(paramVo);
String remark = eventVo.getRemark();
if(StringUtils.isNotBlank(remark)){
    remark = remark.replace("\"", "");
remark = remark.substring(1, remark.length() - 1);
    if(remark.indexOf(",")!=-1){
        String[] strs = remark.split(",");
Map<String, String> map = new LinkedHashMap<String, String>();
        for (String s : strs) {
            String[] ms = s.split(":");
map.put(ms[0], ms[1]);
}
        model.addAttribute("rows", map);
}
}
return "jsonView";



function initRemarkForm() {
    var str = "";
$.ajax({
        type: "POST",
url: '${servletPath}/event/eventRemarkDetail.data',
data: {"eventId": eventId},
async: false,
dataType: "json",
success: function (data, textStatus) {
            var map = data.rows;
for (var key in map) {
                str += '<tr class="par-sp"><th><input class="lay" type="text" id="' + key + '"  value="' + key + '" disabled style="width: 100px;margin-top: 15px;"></th>:<td>' +
                    '<input class="lay" type="text" id="' + key + '" name="' + key + '" value="' + map[key] + '" style="width: 250px;margin-left: 15px;"></td></span>' +
                    '</tr>';
}
            $("#tdremark").html(str);
},
contentType: "application/x-www-form-urlencoded"
});
}

直接用
for (var key in map)

返回的时候显示key用key直接显示,value则需要用map[key]显示

相关推荐