javascript - 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
解决方案
推荐阅读
- angular - 如何在 ag-grid 上显示和使用单选按钮?
- amazon-web-services - EC2 IP 有效,但 URL 获取 ERR_CONNECTION_REFUSED
- c# - Outlook 和 Windows Live Mail 以不同方式显示 html 表(Outlook 显示不想要的,WLM 显示想要的)
- java - JavaFX - 如何刷新损坏的 UI?在 setItems() 空值进入表视图之后
- javascript - Angular 2/4 -- 将单选按钮 [value] 绑定到对象或函数时,为什么这个反应形式的值不更新?
- c++ - 在 gcc 中启用“不同级别的间接”警告/错误
- java - 用其他数组制作一个大数组,如果 FALSE 使它更小
- javascript - 更改为 JavaScript 文件后无法链接网站图标
- python - 我如何使用 Beautiful Soup 来解析击球手的名字?
- javascript - 从内容中删除特定标签并保留简码