简体   繁体   English

ReferenceError: Can't find variable: i (for循环问题)

[英]ReferenceError: Can't find variable: i (for-loop problem)

I made a break from my react native project for about 3 weeks and now I came back and wanted to work on it, unfortunaly the app doesnt even render the first screen components.我从我的 React Native 项目中休息了大约 3 周,现在我回来并想继续它,不幸的是应用程序甚至没有呈现第一个屏幕组件。 I already figured out what the problem is, Im just totaly confused what is going on:我已经弄清楚问题出在哪里,我只是完全弄糊涂了:

    var chatkeys = [];
    var partnerkeys = [];
    var contactsDATA = [];

    await firebase.database().
    ref(`users/${PersonalId}/chats`).
    once('value').
    then(snapshot =>{
        for (i in snapshot.val()){//pulling all chatcodes out of database and pushing into chatkeys
            chatkeys.push(snapshot.val()[i]);
        };
    });

The problem is located in the for-loop.问题出在for循环中。 Here is the error Im receiving:这是我收到的错误:

[Unhandled promise rejection: ReferenceError: Can't find variable: i] [未处理的 promise 拒绝:ReferenceError:找不到变量:i]

  • node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 在 tryCallOne
  • node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0 node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 在_callImmediatesPass
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates __callImmediates 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 在 __guard$argument_0
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard __guard 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
  • [native code]:null in flushedQueue [本机代码]:flushedQueue中的null
  • [native code]:null in callFunctionReturnFlushedQueue [native code]:null in callFunctionReturnFlushedQueue

How can JS not find the variable "i"? JS怎么找不到变量“i”? I never told JS to search for "i" - it's just supposed to be a counter to loop through the whole snapshot.val() array.我从未告诉 JS 搜索“i”——它只是应该是一个遍历整个 snapshot.val() 数组的计数器。 What is going on here?这里发生了什么?

The error states that i is not defined.错误指出未定义i reading your code, I can see that i inside your for loop declaration may be missing the let i variable.阅读您的代码,我可以看到您的 for 循环声明中的i可能缺少let i变量。

Have you tried for (let i in snapshot.val()){你有没有试过for (let i in snapshot.val()){

i is not declared in the scope. Try i没有在 scope 中声明。试试

for (let i in snapshot.val()){//pulling all chatcodes out of database and pushing into chatkeys
            chatkeys.push(snapshot.val()[i]);
        };

OR要么

let i;
for (i in snapshot.val()){//pulling all chatcodes out of database and pushing into chatkeys
            chatkeys.push(snapshot.val()[i]);
        };

I made a break from my react native project for about 3 weeks and now I came back and wanted to work on it, unfortunaly the app doesnt even render the first screen components.我从我的 react native 项目中休息了大约 3 周,现在我回来并想继续工作,不幸的是,该应用程序甚至没有渲染第一个屏幕组件。 I already figured out what the problem is, Im just totaly confused what is going on:我已经弄清楚问题是什么,我只是完全混淆了发生了什么:

    var chatkeys = [];
    var partnerkeys = [];
    var contactsDATA = [];

    await firebase.database().
    ref(`users/${PersonalId}/chats`).
    once('value').
    then(snapshot =>{
        for (i in snapshot.val()){//pulling all chatcodes out of database and pushing into chatkeys
            chatkeys.push(snapshot.val()[i]);
        };
    });

The problem is located in the for-loop.问题出在for循环中。 Here is the error Im receiving:这是我收到的错误:

[Unhandled promise rejection: ReferenceError: Can't find variable: i] [未处理的 promise 拒绝:ReferenceError:找不到变量:i]

  • node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 在 tryCallOne
  • node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0 node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 在 setImmediate$argument_0
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer _callTimer 中的 node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass _callImmediatesPass 中的 node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 在 callImmediates
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates __callImmediates 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0 __guard$argument_0 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard __guard 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 在flushedQueue
  • [native code]:null in flushedQueue 【原生代码】:flushedQueue中的null
  • [native code]:null in callFunctionReturnFlushedQueue 【原生代码】:null in callFunctionReturnFlushedQueue

How can JS not find the variable "i"? JS怎么找不到变量“i”? I never told JS to search for "i" - it's just supposed to be a counter to loop through the whole snapshot.val() array.我从来没有告诉 JS 搜索“i”——它应该是一个循环遍历整个 snapshot.val() 数组的计数器。 What is going on here?这里发生了什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ReferenceError:找不到变量:firebase。我无法将应用程序从 Expo 连接到 Firebase? - ReferenceError: Can't find variable: firebase . I can not connect the App to Firebase from Expo? [未处理的 promise 拒绝:ReferenceError:找不到变量:auth] - [Unhandled promise rejection: ReferenceError: Can't find variable: auth] ReferenceError:找不到变量:firebase 全局代码 - ReferenceError: Can't find variable: firebase global code ReferenceError:在 Expo 上使用 Firebase 时找不到变量:IDBIndex - ReferenceError: Can't find variable: IDBIndex when using Firebase on Expo 找不到变量:firebase - can't find variable : firebase Firebase 在 iPad 上为 Safari; 找不到变量:通知 - Firebase on iPad's Safari; Can't find variable: Notification 如何使用 nohup 在后台运行 python for 循环以执行终端命令? - How do I run python for-loop that executes terminal commands in the background with nohup? 在 GoogleMobileAds 中找不到 GADUnifiedNativeAdView - Can't find GADUnifiedNativeAdView in GoogleMobileAds 我在make API 31的时候找不到这个错误,我的每个项目都有这3个错误 - I can't find this error when I make API 31, there are these 3 errors in each of my projects 聊天API已启用,但我仍然找不到配置选项卡 - Chat API is enabled , but I still can't find configuration tab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM