2013-04-04 23 views
1

我正在以下JSON值:Json to Html使用bootbox?

[{ 
     "employee_id" : 10, 
     "name" : "george" 
    }, { 
     "employee_id" : 20, 
     "name" : "luke" 
    }, { 
     "employee_id" : 30, 
     "name" : "rita" 
    } 
] 

我想值在bootbox以表格形式顯示,我試着下面的代碼,但我不能夠生成它。

bootbox.confirm(
    '<div style="font-size:15px;" class="accordion-body collapse in lst"><i class="icon-circle-arrow-right"</i>&nbsp&nbsp<b>Select the Server Size</b><br/><br/>\n\ 
    <div class="content"><table style="border-collapse: inherit;" class = "table table-striped" cellspacing="0"><thead><tr><th>Select</th><th class="collapse">Name</th></tr></thead><tbody>' 
    for each (var item in obj) { 
    '<tr><td><input type="radio" id="server_size" name="server_size" value='+item.id+'><td>'+item.name+'</td></tbody></table></div></div>' 
     } 
    ,'ok' , 'save'); 
+0

?? – Ihsan 2013-04-04 07:36:54

+0

您是否正在嘗試上面的代碼在PHP或JavaScript。 – 2013-04-04 07:38:05

+0

我正在使用javascript – Cena 2013-04-04 07:40:10

回答

0

請嘗試在外部構建內容,然後將其傳遞到函數中。別忘了連接字符串:

var x = '<div style="font-size:15px;" class="accordion-body collapse in lst">' 
     + '<i class="icon-circle-arrow-right"></i>&nbsp&nbsp' 
     + '<b>Select the Server Size</b><br/><br/>\n' 
     + '<div class="content"><table style="border-collapse: inherit;" ' 
     + 'class = "table table-striped" cellspacing="0"><thead><tr>' 
     + '<th>Select</th><th class="collapse">Name</th></tr></thead><tbody>'; 

for each (var item in obj) { 
     x += '<tr><td><input type="radio" id="server_size" name="server_size"' 
     + ' value='+item.id+'><td>'+item.name+'</td></tbody></table></div></div>'; 
} 

bootbox.confirm(x,'ok','save'); 
+0

感謝您的回覆,這對我有幫助 – Cena 2013-04-04 08:40:33

+0

你是好的。 – Ihsan 2013-04-04 08:59:54