我想建立一個fooTable,其中我的表頭聲明是在另一個窗體上,並且html行字段在另一個窗體上。這裏是集設計,FooTable是未定義的錯誤
親形式
<table class="footable table" id="L-EGY-TRG-501-00BP_fooTable" >
<thead>
<tr>
<th data-sort-initial="true" data-toggle="true">Employed by</th>
<th>Category</th>
<th data-hide="phone, tablet">Sub-Category</th>
<th data-hide="phone, tablet">Attendee Count</th>
</tr>
</thead>
<tbody id="L-EGY-TRG-501-00BP_fooTableBody">
</tbody>
</table>
TRG排形式
<table>
<tr id="yyy" data-losstype="fin-row" data-GUID="L-EGY-TRG-ROW-501-003H">
<td>
<input type="text" class="form-control" id="yyy_EmployedBy" name="yyy_EmployedBy" value="" >
</td>
<td>
<input type="text" class="form-control" id="yyy_Category" name="yyy_Category" value="" >
</td>
<td>
<input type="text" class="form-control" id="yyy_SubCategory" name="yyy_SubCategory" value="" >
</td>
<td>
<input type="text" class="form-control" id="yyy_attendeecount" name="yyy_attendeecount" value="" >
</td>
<td>
<button type="button" class="btn btn-sm btn-default btn-rounded" onClick="#" title="Add Attendee Row">
<i class="fa fa-plus"></i>
</button>
<button type="button" class="btn btn-sm btn-default btn-rounded removeRowLink" onClick="#" title="Remove Attendee Row">
<i class="fa fa-minus"></i>
</button>
</td>
</tr>
</table>
這是我在嘗試使用jQuery做,
$(document).ready(function(){
guid="xxxxx"
prepTable("/pro?openform,guid); //
});
function prepTable(surl,guid){
$.get(surl, function(data) {
var footable = $(data).find('.footable').footable();
guid="xxxxx";
buildFooTable(guid,"/trg-row?openform");
});
}
funtion buildFooTabl(containerID,surl) {
$.get(surl, function(data) {
var $row = $(data).find('#yyy');
var footable = $('#' + containerID + '_fooTable').data('footable');
var rowid = $row.attr('data-GUID');
$row.find('[id*=yyy]').each(function() {
var id = this.id || "";
this.id = id.replace('yyy', rowid)
});
$row.find('[name*=yyy]').each(function() {
var nm = this.name || "";
this.name = nm.replace('yyy', rowid)
});
$row.attr('id',rowid);
footable.appendRow($row);
});
但得到錯誤「TypeError :footable是未定義的「在這條線上的錯誤,但是fooTable id正確。
var footable = $('#' + containerID + '_fooTable').data('footable');
有一個在DOM沒有這樣的元素與ID =「xxxxx_fooTable」 – DinoMyte
@DinoMyte,燁它的存在..Check我的編輯 – Rishi