[英]Load data from JavaScript into html table
I have problems to load data from javascript into a html table. 我无法将数据从javascript加载到html表中。 So here is my java script code...
所以这是我的Java脚本代码...
//success data
$('#A').empty();
$.each(data, function(index, aObj){
//$('#A').append('<option value="' + aObj.id + '">'+aObj.note+'</option>');
$('#A').append('<tr><td style="' + aObj.id + '">'+aObj.note+'</td style></tr>');
});
The // option value works in a select box. //选项值在选择框中起作用。 But now I want to have the aObj.note into a table between the td style tags.
但是现在我想将aObj.note放入td样式标签之间的表中。
table class="table table-bordered table-striped" name="A" id="A">
thead>
tr>
th class="">Note/th>
/tr>
/thead>
tbody>
@foreach($alleSpiele as $alleSpieleOutput)
tr>
td style="">/td style>
/tr>
@endforeach
/tbody>
/table>
You could try like this: 您可以这样尝试:
var table = $("#table tbody");
$.each(data, function(idx, elem){
table.append("<tr><td>"+elem.username+"</td><td>"+elem.name+"</td> <td>"+elem.lastname+"</td></tr>");
});
More information can be found here: http://api.jquery.com/jQuery.each/ 可以在这里找到更多信息: http : //api.jquery.com/jQuery.each/
Okay I have following solution... 好吧,我有以下解决方案...
//success data
$('#A').empty();
$.each(data, function(index, valueAusData){
$('#myTable tr:last').after('<tr>')
$('#myTable tr:last').after('<td>'+ valueAusData.note+'</td>')
$('#myTable tr:last').after('<td>'+ valueAusData.note+'</td>')
$('#myTable tr:last').after('</tr>')
});
And here my table 这是我的桌子
<table class="table table-bordered table-striped" id="myTable">
<tbody>
<tr>
<th>Note</th>
<th>Note Zwei</th>
</tr>
</tbody>
</table>
I know that after is not the correct statement here. 我知道之后的说法不正确。 But with which statement I have to replace after that alle values are under the tr td in the html table?
但是,在alle值在html表的tr td下之后,我必须用哪条语句替换?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.