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

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

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

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

public String lotteryList(){

int actityId=1;

List list=lotteryDrawService.getLotteryList(actityId);

String str = "";

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

str += "[";

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

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);

}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章