使用Redux和Table显示来自多个端点的数据

时间:2020-07-10 09:51:03

标签: reactjs redux react-redux

我想使用redux将来自多个源的数据显示到一个表中。示例数据

url:'/product/'
products :[
    {
        id: 1,
        name:'machine gun',
        category: 1
    },
    {
        id: 2,
        name:'water pistol',
        category: 2
    },
    
    
]
endpoint:'/category/'
category:[
    {
        id:1,
        name:'main tool'
    },
    {
        id:2,
        name:'secret weapon'
    }
]
endpoint:'/stock/?product=1,current=true'
stock:[
    {
        id:1,
        product:1,
        current:false,
        currentStock:10
    },

]

商店-> 1)产品2)类别3)库存

我的问题是:

  1. 如果我从后端查询所有类别,库存和产品,它将非常昂贵

  2. 我希望表格具有以下字段 |产品名称|类别|库存数量| 友善的帮助 这是我获取产品库存的示例操作

     export function getStock(productId) {
    
     const request = axios.get('http://localhost:8000/productstock/',
         {
         params: {
             product: productId,
             current: true
         }
     }
     );
    
     return dispatch =>
         request.then(response =>
             dispatch({
                 type: GET_STOCK,
                 payload: response.data
             })
         );
    

    }

0 个答案:

没有答案