Wrap the rendering code inside a function that the data can be passed to.
This commit is contained in:
parent
d297a1ac62
commit
6cd4ddb71b
|
@ -9,25 +9,34 @@
|
||||||
var rowTemplate = wp.template( 'wc-tax-table-row' ),
|
var rowTemplate = wp.template( 'wc-tax-table-row' ),
|
||||||
$tbody = $('#rates');
|
$tbody = $('#rates');
|
||||||
|
|
||||||
// Blank out the contents.
|
/**
|
||||||
$tbody.innerHTML = '';
|
* Build the table contents.
|
||||||
|
* @param rates
|
||||||
|
*/
|
||||||
|
function renderTableContents( rates ) {
|
||||||
|
// Blank out the contents.
|
||||||
|
$tbody.empty();
|
||||||
|
|
||||||
// Populate $tbody with the current page of results.
|
// Populate $tbody with the current page of results.
|
||||||
$.each( data.rates, function ( id, rowData ) {
|
$.each( rates, function ( id, rowData ) {
|
||||||
$tbody.append( rowTemplate( rowData ) );
|
$tbody.append( rowTemplate( rowData ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Initialize autocomplete for countries.
|
// Initialize autocomplete for countries.
|
||||||
$tbody.find( 'td.country input' ).autocomplete({
|
$tbody.find( 'td.country input' ).autocomplete({
|
||||||
source: data.countries,
|
source: data.countries,
|
||||||
minLength: 3
|
minLength: 3
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Initialize autocomplete for states.
|
||||||
|
$tbody.find( 'td.state input' ).autocomplete({
|
||||||
|
source: data.states,
|
||||||
|
minLength: 3
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTableContents( data.rates );
|
||||||
|
|
||||||
// Initialize autocomplete for states.
|
|
||||||
$tbody.find( 'td.state input' ).autocomplete({
|
|
||||||
source: data.states,
|
|
||||||
minLength: 3
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.wc_tax_rates .remove_tax_rates').click(function() {
|
$('.wc_tax_rates .remove_tax_rates').click(function() {
|
||||||
if ( $tbody.find('tr.current').length > 0 ) {
|
if ( $tbody.find('tr.current').length > 0 ) {
|
||||||
|
|
Loading…
Reference in New Issue