Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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
Javascript 如何传递sectionlist sectionHeader';减速器的s指数?_Javascript_Node.js_Mongodb_React Native_Redux - Fatal编程技术网

Javascript 如何传递sectionlist sectionHeader';减速器的s指数?

Javascript 如何传递sectionlist sectionHeader';减速器的s指数?,javascript,node.js,mongodb,react-native,redux,Javascript,Node.js,Mongodb,React Native,Redux,通过使用SectionList来映射具有索引的项,我成功地映射了节的索引并将状态传递给reducer,但是,节头有一个不同的索引,并且希望对其执行相同的操作。如果可能的话,帮我举一些例子。这是我为一个食品技术应用程序开发的东西,我想在应用程序中实现购物车功能 部分列表: <SectionList sections={this.props.user.dailyMenuData.item.map( ({category, data}, index2) => (

通过使用
SectionList
来映射具有索引的项,我成功地映射了节的索引并将状态传递给reducer,但是,节头有一个不同的索引,并且希望对其执行相同的操作。如果可能的话,帮我举一些例子。这是我为一个食品技术应用程序开发的东西,我想在应用程序中实现购物车功能

部分列表

<SectionList
      sections={this.props.user.dailyMenuData.item.map(
        ({category, data}, index2) => ({category, data, index2}),
      )}
      keyExtractor={this.keyExtractor}
      renderItem={this.renderMenu}
      renderSectionHeader={({section: {category, index2}}) => (
        <CText style={styles.headerStyle}>{category}</CText>
      )}
    />
AddtoCart
Reducer正在动态获取
data[]
的索引值,但是它无法从调用的API获取
项[]
的索引。减速器代码如下所示:

case ADDTOCART:
  return update(state, {
    dailyMenuData: {
      item: {
        1: {
          data: {
            [payload.index]: {
              quantity: {
                $set:
                  state.dailyMenuData.item[1].data[payload.index].quantity +
                  1,
              },
            },
          },
        },
      },
    },
  })

不过,我还是设法完成了。我无法更新减速器中的状态。我的AddtoCart Reducer有映射数据,它从DB中获取数量,这是我不想要的。我把它当作一个临时解决办法,我又成功地把它做完了!!!。我从SectionList中的sections属性传递了itemIndex。我的代码看起来像这样。但是,sections={this.props.user.menu.item.map({category,data},itemIndex)=>({category,data,itemIndex}),我设法完成了。我无法更新减速器中的状态。我的AddtoCart Reducer有映射数据,它从DB中获取数量,这是我不想要的。我把它当作一个临时解决办法,我又成功地把它做完了!!!。我从SectionList中的sections属性传递了itemIndex。我的代码看起来像这样。sections={this.props.user.menu.item.map({category,data},itemIndex)=>({category,data,itemIndex}),)}
case ADDTOCART:
  return update(state, {
    dailyMenuData: {
      item: {
        1: {
          data: {
            [payload.index]: {
              quantity: {
                $set:
                  state.dailyMenuData.item[1].data[payload.index].quantity +
                  1,
              },
            },
          },
        },
      },
    },
  })