I have the below functions as a part of JS.
_RenderVendorView
will trigger when clicking on a row of the table of vendors and it will show vendor details page,
And in vendor details view page there is a button with class .vendorsListButton
, which will go back to table of vendors, means will trigger _RenderVendorsList
var _RenderVendorsList = function () {
$(document).on('click', '.vendorsListButton', function () {
jQuery.ajax({
url: "/purchases/render_vendors_list",
type: "POST",
success:function(data){
$data = $(data); // the HTML content that controller has produced
$('#vendorcontainer').hide().html($data).fadeIn();
_TableVendors();
_RenderVendorForm();
}
});
});
};
var _RenderVendorView = function () {
$(document).on('click', '#tableVendors tbody td:not(:first-child)', function () {
if ($(this).index() == 4 ) {
// provide index of column in which we want prevent row click here is column of 4 index
return;
}
else{
var rowdata = $('#tableVendors').DataTable().row($(this).parents('tr') ).data();
jQuery.ajax({
url: "/purchases/render_vendor_view",
type: "POST",
data: {vendor:rowdata.vendor_id},
success:function(data){
$data = $(data); // the HTML content that controller has produced
$('#vendorcontainer').hide().html($data).fadeIn();
_TableBills(rowdata);
_TableExpenses(rowdata);
_RenderVendorsList();
}
});
}
});
};
Now, problem is that 1st click on row open vendor page and 1st click on .vendorsListButton
go back to vednors list,
2nd click on row also open vendor page, but when 2nd click on .vendorsListButton
will run _RenderVendorsList
two times, and on each iterate function run increase ...
Not sure why it running multiple times on each forth and back.
What is wrong with this loop?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…