1

我得到以下 JSON 值:

[{
        "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');
4

1 回答 1

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');
于 2013-04-04T07:43:56.263 回答