0

I wrote a method that is supposed to execute a callback, but the callback isnt being executed:

buildTable('lt', 'viewltDetails', commonTireColumns, function(error) {
if(error) {
    console.log(error);
} else {
    console.log('calculating');
    calculatedPricing();
}
});

My buildTable function - it essentially creates a datatable using the aldeed-tabular package:

function buildTable(tblName, detailsBtn, columnDetails) {
var columns = [];
for(var key in columnDetails) {
      columns.push({
        data: columnDetails[key].data, 
        title: columnDetails[key].title, 
        width: columnDetails[key].width
      });
    };
columns.push({
    title: "Quantity",
    tmpl: Meteor.isClient && Template.itemQuantityCell,
    width: "2%"
});
columns.push({
    title: "Details",
    tmpl: Meteor.isClient && Template[detailsBtn],
});
columns.push({
    title: "Action",
    tmpl: Meteor.isClient && Template.addToCartCell,
});

TabularTables[tblName] = new Tabular.Table({
    name: tblName,
    changeSelector: function(selector, userId) {
        return selector;
    },
    collection: Products,
    pub: "tabular_Products",
    columns: columns,
    extraFields: ['priceFET', 'invoicePrice', 'category']
})
};

The buildTable function works fine, but it's not executing the console.log('calculating') and calculatePricing() commands, although the function isn't throwing any errors.

My calculatePricing function looks like:

calculatedPricing: function() {
    var price = 300;
    return price;
};

Can someone help? Thanks!!

5
  • 1
    You'll almost definitely need to share buildTable so we can see how the callback should be invoked and what error is expected to be Commented Aug 4, 2015 at 14:01
  • You are probably not invoking the callback properly in buildTable Commented Aug 4, 2015 at 14:01
  • Your calculatedPricing definition has wrong syntax. FYI: calculatedPricing is not a callback in your code Commented Aug 4, 2015 at 14:04
  • I added my buildTable() code! Commented Aug 4, 2015 at 14:05
  • 1
    so ... where exactly is buildTable calling anything? the fourth argument (which is the callback in your first code snippet) isn't even defined (not that that is a problem as such) Commented Aug 4, 2015 at 14:06

2 Answers 2

3

Please try like this. You add a calback function but you don't have it at a parameter so you never call it on your function.

 function buildTable(tblName, detailsBtn, columnDetails, callback) {
         //your code here
         if(typeof callback === "function"){
           callback();
         }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

callback in example expects an argument indicating error
1

You need to add an argument for the callback to your buildTable function

change:

function buildTable(tblName, detailsBtn, columnDetails) {

to:

function buildTable(tblName, detailsBtn, columnDetails, callback) {

then, call it:

callback(someError);

2 Comments

callback in example expects an argument indicating error
good point, but I didn't see where an error is being caught, just trying to provide direction here...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.