为什么我的代码显示“找不到播放器”?

时间:2019-04-28 01:05:20

标签: javascript

所以我有这个命令,如果发现了玩家的状态,该命令应该显示该玩家的状态,否则显示未找到该玩家的状态。搜索播放器并转到上一屏幕后,显示“找不到播放器”。我以为是因为找到播放器后我的循环继续运行,并且布尔值变为false,所以我添加了break语句。无法工作

function Search(Table, Stat1, Stat2, Stat3, Stat4, Stat5) {
    onEvent("Search2.btn", "click", function() {
        readRecords(Table, {}, function(records) {
            var SearchPlayer = getText("text_input1");
            var found = false;
            for (var i = 0; i < records.length; i++) {
                if ((records[i]).Player == SearchPlayer) {
                    setScreen("DisplaySearch");
                    setText("label3", records[i].Player + " Stats" + "\n" + records[i][Stat1] + " " + Stat1 + "\n" + records[i][Stat2] + " " + Stat2 + "\n" + records[i][Stat3] + " " + Stat3 + "\n" + records[i][Stat4] + " " + Stat4 + "\n" + records[i][Stat5] + " " + Stat5 + "\n");
                    setText("text_input1", "");
                    setText("label5", "");
                    found = true;
                    break;
                } else if ((found == false)) {
                    setText("label5", "Player Not Found");
                }
            }
        });
    });

0 个答案:

没有答案