如果我应用断点并在调试模式下运行应用程序,则应用程序可以完美运行
My application runs perfectly if I apply breakpoints and run the application in debugging mode otherwise not
我使用Ionic框架来开发我的应用程序,我有Firebase作为后端。我设置了断点并尝试运行应用程序,它工作得很好。但是,如果我在没有调试器的情况下运行应用程序,我看到Firebase数据库中的值没有改变,而且页面转换失败。以这种方式运行的任何可能的原因
部分html:
<a class="button button-balanced button-block" id="snooker-button1" ng-click = "setTitle('Table 1')" ui-sref="tableX">Table 1</a>
<a class="button button-balanced button-block" id="snooker-button2" ng-click = "setTitle('Table 2')" ui-sref="tableX">Table 2</a>
<a class="button button-balanced button-block" id="snooker-button3" ng-click = "setTitle('Table 3')" ui-sref="tableX">Table 3</a>
<a class="button button-balanced button-block" id="snooker-button4" ng-click = "setTitle('Table 4')" ui-sref="tableX">Table 4</a>
<a class="button button-assertive button-block" id="snooker-button5" ng-click = "setTitle('Table 5')" ui-sref="tableX">Table 5</a>
<a class="button button-balanced button-block" id="snooker-button6" ng-click = "setTitle('Table 6')" ui-sref="tableX">Table 6</a>
<!-- <div style="" class="button-bar"></div> -->
<div style="" class="button-bar">
<button class="button button-calm button-block button-outline" style="font-weight:600;" id="page3-button11" ng-click = "gameEngine_v()" >Start</button>
<button class="button button-calm button-block button-outline" style="font-weight:600;" id="page3-button12"ng-click = "gameEngine_v_stp()" >Stop</button>
Controller.js文件的一部分
$scope.setTitle = function(table_title)
{
// table_title = "Table 1 is the title";
table_title_g = table_title ;
var table_db_ref_copy = new Firebase("https://glaring-torch-3069.firebaseio.com/tables/"); //database ref for the table
var str_table_db_ref_copy = "https://glaring-torch-3069.firebaseio.com/tables/";
var table_number = table_title_g.charAt(6);
var str_table = "table";
var str_table_final = str_table.concat(table_number);// try str_table = str_table.concat(table_number)
var str_players = "/players";
var str_table_db_ref_players = str_table_db_ref_copy.concat(str_table_final);
var str_table_db_ref_players_fb = new Firebase(str_table_db_ref_players);
var players_at_table_snapshot = null;
var get_players_at_table =
function(players_at_table_snapshot_actual)
{
players_at_table_snapshot = null;
players_at_table_snapshot = players_at_table_snapshot_actual;
};
str_table_db_ref_players_fb.on('value',get_players_at_table);
str_table_db_ref_players_fb.off('value',get_players_at_table);
var players_at_table_data = players_at_table_snapshot.val();
player_one_v = players_at_table_data.players.player1;
player_two_v = players_at_table_data.players.player2;
player_three_v = players_at_table_data.players.player3;
player_four_v = players_at_table_data.players.player4;
};
var temp_ind = 0;
var intvId = 0;
$scope.gameEngine_v = function()
{
// if(temp_ind == 1)
// {
// intvId = setInterval(gameEngine, 3000);
intvId = setTimeout(gameEngine, 3000);
// gameEngine(temp_ind);
// }
// if(temp_ind == 0)
// {
// clearInterval(intvId);
// }
};
$scope.gameEngine_v_stp = function()
{
// clearInterval(intvId);
clearTimeout(intvId);
// gameEngine(temp_ind);
};
//tables_snapshot https://glaring-torch-3069.firebaseio.com/tables
var gameEngine = function(){
// if(game_s_var == 1){
var table_db_ref = new Firebase("https://glaring-torch-3069.firebaseio.com/tables/"); //database ref for the table
players_db_ref = new Firebase("https://glaring-torch-3069.firebaseio.com/players/"); //database ref for the list of potential players
str_players_db_ref = "https://glaring-torch-3069.firebaseio.com/players/";
// Basic usage of .once() to read the data located at firebaseRef.
counter = 0;
var tables_snapshot = null;
var players_snapshot = null;
var get_tables_snapshot =
function(datasnapshot_tables)
{
tables_snapshot = null;
tables_snapshot = datasnapshot_tables;
};
var get_players_snapshot =
function(datasnapshot_players)
{
players_snapshot = null;
players_snapshot = datasnapshot_players;
};
var msg = null;
var onComplete = function(error) {
msg = null;
if (error) {
msg = "Failed Synchronization";
} else {
msg = "Success";
}
};
table_db_ref.on('value',get_tables_snapshot);
table_db_ref.off('value',get_tables_snapshot);
tables_snapshot.forEach(
function(childSnapShot)
{
var key = childSnapShot.key();
var data = childSnapShot.val();
var str_1 = "https://glaring-torch-3069.firebaseio.com/tables/";
var str_2 = "/players";
var str_3 = str_1.concat(key,str_2);
var t_mode = data.mode;
var players = new Firebase(str_3);//path for players at the table
players_db_ref.on('value',get_players_snapshot);
players_db_ref.off('value',get_players_snapshot);
var count = 0;
var flag = 0;
if(t_mode == 'singles' && flag == 0)
{
players_snapshot.forEach(
function(player_snaphot)
{
count = count + 1;
var player_data = player_snaphot.val();
var player_key = player_snaphot.key();
var str_currentPlayer = str_players_db_ref.concat(player_key);//holds the url of the current player
var currentPlayer_ref = new Firebase(str_currentPlayer);
var player_emp_id = player_data.emp_id;
if(count == 1)
{
players.update(
{
player1:player_emp_id
}
);
currentPlayer_ref.remove(onComplete);
var str_test = 'i am here !!';
}
else if (count == 2)
{
players.update(
{
player2:player_emp_id
}
);
currentPlayer_ref.remove(onComplete);
}
else
{
flag = 1;
// return true; // to go out of forEach loop
}
}
);
// var d = setTimeout(gameEngine(1), 3000);
}
count = 0 ;
if(t_mode == 'doubles' && flag == 0)
{
players_snapshot.forEach(
function(player_snaphot)
{
count = count + 1;
var player_data = player_snaphot.val();
var player_key = player_snaphot.key();
var player_emp_id = player_data.emp_id;
if(count == 1)
{
players.update({ player1:player_emp_id });
currentPlayer_ref.remove(onComplete);
}
else if (count == 2)
{
players.update({ player2:player_emp_id });
currentPlayer_ref.remove(onComplete);
}
else if (count == 3)
{
players.update({ player3:player_emp_id });
currentPlayer_ref.remove(onComplete);
}
else if (count == 4)
{
players.update({ player4:player_emp_id });
currentPlayer_ref.remove(onComplete);
}
else
{
flag = 1; // to go out of forEach loop
}
}
);
}// end of 'doubles' mode elseif
}
);
// }
};
// var d = setTimeout(gameEngine(1), 3000);
})
正如David已经评论的那样,这通常是由于竞争条件而发生的。在你的JS的情况下,虽然它是因为异步调用没有妥善处理。Firebase dbref.on
为异步调用。当从服务器接收到数据时,该函数将执行。因此,tables_snapshot
&players_at_table_snapshot
必须在各自的异步处理函数内。
相关文章:
- ng应用程序使脚本无限运行
- 从Spring应用程序运行PhantomJS以获取网页缩略图
- AngularJS/Protactor:使用角种子基本应用程序运行量角器时出错
- 从web应用程序运行.exe文件
- 如何在流打开时保持节点应用程序运行
- 从 HTML 应用程序与 Flex 应用程序运行时出现 ActiveXObject 错误
- Intellij IDEA 12.1.7 JavaScript 文件在应用程序运行时不更新
- 推迟在应用程序运行angularjs上创建控制器/服务
- 将node-webkit作为node.js应用程序运行
- 当我在网站上运行时,我如何构建我的应用程序以使用localStorage,当我作为chrome应用程序运行时,如何构建c
- 是否有可能使它清楚,如果应用程序运行在网站的根下或在js应用程序下
- 我应该如何从Java应用程序运行NodeJS
- 离子应用程序运行功能在第二次点击
- Android应用程序-运行一次JavaScript函数,然后在应用程序更新之前不要再次运行
- HTML5移动应用程序运行时,手机屏幕关闭
- Angularjs应用程序运行在本地主机上,而不是在heroku上
- 简单的Express.js应用程序运行错误
- 什么是web应用程序运行时
- 当作为 Web 应用程序运行时,对象不支持 IE11 上的属性或方法“create”,在浏览器中直接打开 HTML 时很
- Javascript全局变量只能在应用程序运行后访问