Wrap the rendering code inside a function that the data can be passed to.

This commit is contained in:
George Stephanis 2015-08-07 15:44:10 -04:00
parent d297a1ac62
commit 6cd4ddb71b
1 changed files with 25 additions and 16 deletions

View File

@ -9,11 +9,16 @@
var rowTemplate = wp.template( 'wc-tax-table-row' ), var rowTemplate = wp.template( 'wc-tax-table-row' ),
$tbody = $('#rates'); $tbody = $('#rates');
/**
* Build the table contents.
* @param rates
*/
function renderTableContents( rates ) {
// Blank out the contents. // Blank out the contents.
$tbody.innerHTML = ''; $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 ) );
} ); } );
@ -28,6 +33,10 @@
source: data.states, source: data.states,
minLength: 3 minLength: 3
}); });
}
renderTableContents( data.rates );
$('.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 ) {