Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如果来自同一函数,如何使用内部变量?_Reactjs_React Native - Fatal编程技术网

Reactjs 如果来自同一函数,如何使用内部变量?

Reactjs 如果来自同一函数,如何使用内部变量?,reactjs,react-native,Reactjs,React Native,现在我想从if中得到一个变量,在同一个函数中,如下所示 renderItemBox() { const { store } = this.props; const currentScreen = this.props.navigation.state.routeName; AsyncStorage.getItem('openingGenre') .then((openingGenreValue) => { if (currentScreen === 'EachShopGenre

现在我想从if中得到一个变量,在同一个函数中,如下所示

renderItemBox() {
const { store } = this.props;
const currentScreen = this.props.navigation.state.routeName;
AsyncStorage.getItem('openingGenre')
  .then((openingGenreValue) => {
    if (currentScreen === 'EachShopGenreScreen') {
      if (openingGenreValue === 'food') {
        const items = this.store.restourantStore.Items;
      } else {
        Alert.alert('予期せぬ不具合が発生いたしました。再度お試し下さい');
      }
  });
return items.map((value, index) => (


//////
)
但是,此代码不起作用,我无法从items.map上的IF获取“items”~~~~

为什么会这样


有人能帮我吗。

您需要在函数范围中将let声明为空数组,然后执行if语句。 或者至少这是一种方法。
顺便说一句,这更像是一个JavaScript问题。

您的代码不清楚。。。请提供完整的方法或类,以便更好地理解…我知道…但我的代码太长…基于您的代码,您希望从退货处访问您的项目,对吗?没错。我想要。这能回答你的问题吗?