首页 > 解决方案 > Javascript function returning undefined instead of integer value

问题描述

Hi I am calling a function get_location_tcount(1); whose declaration is like

function get_location_tcount(id,callback) {
    myDB.transaction(function (transaction) {
        var t_sql = 'select * from tbl_locations where location_structure_id = "' + id+ '"';
        transaction.executeSql(t_sql, [], function (tx, results) {
            var length = results.rows.length;
            callback(length);
        }, null);
    });
 }

This how I am calling it

var t_count = 0;
get_location_tcount(1,function(total_count){
    alert(total_count); // Alerting the value
    t_count = total_count; // but not setting in variable t_count
});

and I am using the t_count in

shelfs_list += '<p>Total Count : ' + t_count + '</p>';

I am setting it just after calling the function

标签: javascript

解决方案


推荐阅读