微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 redux-selectors 从我的数据中获取这些项目

如何解决如何使用 redux-selectors 从我的数据中获取这些项目

我有一个对象的数据通知,其中有一个对象也带有路线名称名称,然后在该对象内部再次有路线名称标题和项目,但项目是数组形式。 然后使用来自 redux 的选择器,我在数据中插入动态路由名称并使用参数名称/路径,使用 params。如果您查看第二个组件下方的代码,我使用 match.path/:collctionId 来匹配从商店获取的产品路径和作为参数的 collectionId,我使用 redux 选择器将 routeName 与 collectionId 匹配。因此,我没有始终如一地显示 collectionId,而是根据您所在的路线动态显示路线名称

const Shop = ({ match }) => {
 
    return (
      <div className="shop-page">
        <Route exact path={`${match.path}`} component={collectionOverview} />
        <Route excat path={`${match.path}/:collectionId`} component={collectionPage} />  
    </div>
      
    )
  }

这是使用OwnProps.match.params.collectionId获取routeName的CollectionPage,并显示我从选择器中获取的动态routeName..

const CollectionPage = ({ collection }) => {
  const { title,items } = collection;
  return (
    <CollectionPageContainer>
      <CollectionTitle>{title}</CollectionTitle>
      <CollectionItemsContainer>
        {items.map(item => (
          <>
            <CollectionItem key={item.id} item={item} />
          </>
        ))}
      </CollectionItemsContainer>
    </CollectionPageContainer>
  );
};

const mapStatetoProps = (state,ownProps) => ({
  collection: selectCollection(ownProps.match.params.collectionId)(state)
});

以下是我的 dataForm 代码:​​

const SHOP_DATA = {

帽子:{ 编号:1, title: '帽子',路线名称:'帽子', 项目: [ { _id: 1,name: '棕色边缘',imageUrl: 'https://i.ibb.co/ZYW3VTp/brown-brim.png',价格:25 },{ _id: 2,name: '蓝色豆豆',imageUrl: 'https://i.ibb.co/ypkgK0X/blue-beanie.png',价格:18 },{ _id: 3,name: '棕色牛仔',imageUrl: 'https://i.ibb.co/QdJwgmp/brown-cowboy.png',价格:35 },{ _id: 4,name: '灰色边缘',imageUrl: 'https://i.ibb.co/RjBLWxB/grey-brim.png',{ _id: 5,name: '绿豆豆',imageUrl: 'https://i.ibb.co/YTjW3vF/green-beanie.png',{ _id: 6,name: '棕榈树帽',imageUrl: 'https://i.ibb.co/rKBDvJX/palm-tree-cap.png',价格:14 },{ _id: 7,name: '红豆豆',imageUrl: 'https://i.ibb.co/bLB646Z/red-beanie.png',{ _id: 8,name: '狼帽',imageUrl: 'https://i.ibb.co/1f2nWMM/wolf-cap.png',{ _id: 9,名称:'蓝色回弹', imageUrl: 'https://i.ibb.co/X2VJP2W/blue-snapback.png',价格:16 } ] },

但是在这里,我截取了数据,因为显示所有数据很长。但这是数据的格式... 因此,如您所见,我只想使用选择器插入项目并创建了一个产品详细信息页面。 , 请告诉我。我愿意企业。谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。