2013-04-04 41 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