JS eval函數(後臺組裝成對象,前臺 EVAL 接收,轉換成須要的對象屬性值)

JS eval函數(後臺組裝成對象,前臺 EVAL 接收,轉換成須要的對象屬性值)必須加載附件html

第一步:後臺action 把須要的數據集轉換成:ide

[{name:'value',pwd:'value'},{name2:'value',pwd2:'value'}] 格式的字符函數

public String lotteryList(){this

int actityId=1; spa

List list=lotteryDrawService.getLotteryList(actityId);htm

String str = "";對象

if(list != null && list.size() > 0){get

str += "[";it

for(int i = 0 ; i < list.size(); i++){io

Map m = (Map) list.get(i);

str += "{prizeDesc:'" + m.get("PRIZE_DESC") + "',";

if(i + 1< list.size()){

str += "winningUserPhone:'" + m.get("WINNING_USER_PHONE") + "'},";

}else{

str += "winningUserPhone:'" + m.get("WINNING_USER_PHONE") + "'}";

}

}

str += "]";

}

this.setWriterPrint(str);

return null ;

}

 

第二步:前臺JS 代碼,解析後臺須要的集合屬性值

$(document).ready(function(){

getLotteryList();

});

 

function getLotteryList(){

var uri = "http://bj.homescn.com/lotteryDraw/lotteryList.do?actityId=1";

send_request(uri, function(data){

if(typeof(data) !='undefined' && data != ''){

var arr = eval(data);

var html = "<marquee  onMouseOver=\"this.stop()\" onMouseOut=\"this.start()\" align=center direction=up scrollamount=1  scrolldelay=3 valign=middle behavior=\"scroll\">";

for(var i = 0; i < arr.length; i++){

var obj = arr[i];

html += "<li>" + obj.prizeDesc + "&nbsp;&nbsp;&nbsp;" + obj.winningUserPhone +"</li>";

}

html += "</marquee>";

document.getElementById("marquee_list").innerHTML = html;

}

}, false);

}

相關文章
相關標籤/搜索