2022.2

Table Of Contents
var row = query("tbody tr", results).clone();
query("tbody", results).append(row);
Thefollowingscriptclonesanexistingtablerowtomatchthenumberofrowsinadetailtable.After-
wardsititeratesovertherowstopopulatethefields.
// Create the number of rows based on the records in the detail table
// We start at 1 so the boilerplate row is used too and there is no need to delete that row
for(var r = 1; r < record.tables['detail'].length; r++) {
results.parent().append(results.clone());
}
// Iterate over the rows and populate them with the data from the accompanying data row
query("#table_2 > tbody > tr").each(function(i) {
this.find('@ItemNumber@').text( record.tables['detail'][i].fields["ItemNumber"]);
this.find('@ItemOrdered@').text( record.tables['detail'][i].fields["ItemOrdered"]);
this.find('@ItemTotal@').text( record.tables['detail'][i].fields["ItemTotal"]);
this.find('@ItemDesc@').text( record.tables['detail'][i].fields["ItemDesc"]);
this.find('@nr@').text(i);
});
Thefollowingscriptclonesandpopulatesaboilerplaterow.Oncecompletedyouwillneedtohidethe
boilerplaterow.
for(var i = 0; i < record.tables['detail'].length; i++) {
var row = results.clone(); //Clone our boilerplate row
row.find('@ItemNumber@').text( record.tables['detail'][i].fields["ItemNumber"]);
row.find('@ItemOrdered@').text( record.tables['detail'][i].fields["ItemOrdered"]);
row.find('@ItemTotal@').text( record.tables['detail'][i].fields["ItemTotal"]);
row.find('@ItemDesc@').text( record.tables['detail'][i].fields["ItemDesc"]);
row.find('@nr@').text( i );
results.parent().append(row);
}
// Hide our boilerplate row (note that this doesn't really delete the row).
results.hide();
closest()
Thisfunctiongetsthefirstparentelementthatmatchesaselector,bytestingtheelementitselfandtra-
versingupthroughitsancestorsintheDOMtree.(InHTML,aparentisanelementthatcontains
anotherelement.)
Thefunctioncanbeusedfor:
l
Theelementsthatmatchtheselectorofascript(see"results"onpage1301).
l
Oneelementthatmatchestheselectorofascriptthatrunsfor"Eachmatchedelement"(see
"this"onpage1237and"Settingthescopeofascript"onpage813).
l
Theelementsreturnedbyaqueryinthetemplate(see"query()"onpage1197).
Togetachildelementorallchildelements,usechildren()(see"children()"onthepreviouspage).
Page 1251