reactjs - 如何在同一页面上传递两个查询集?(django rest框架和react)
问题描述
我想在同一个 url 中显示两个查询集值。我有我的主页,我在其中传递所有产品列表,在同一页面上的该部分之后,我试图根据类别显示产品,例如第一个最近的产品,然后是下一部分所有自行车(基于类别)。
@api_view(['GET'])
def getProducts(request):
products = Product.objects.all()
p = Product.objects.all().filter(category = 1)
context = {
"request": request,
}
first_serializer = ProductSerializer(products, many= True, context=context)
second_serializer = ProductSerializer(p, many= True, context=context)
response = first_serializer.data + second_serializer.data
return Response(response)
这是我的反应页面
最近的产品
{loading ? <Loader />
: error ? <Message variant='danger'>{error}</Message>
:
<Row>
{products.map(product => (
<Col key={product._id} sm={12} md={6} lg={4} xl={3}>
<Product product={product} />
</Col>
))}
</Row>
}
我想要这样的相同程序
<Row>
{p.map((product) => (
<Col key={product._id} sm={12} md={6} lg={4} xl={3}>
<Product product={product} />
</Col>
))}
</Row>
<Row>
但我无法映射 p 对象。我现在该怎么办?我正在使用 redux 的反应。
解决方案
推荐阅读
- c# - 如何在组件的类中注入 DateTimeProvider / wrapper 依赖项但不使用构造函数?
- scala - Spark Dataframes 多个 JOIN
- c# - 用 C# 中的相应 html 替换多个引号标签
- bioinformatics - Snakemake 在两个不同的通配符子集上发布运行规则
- reactjs - 重新渲染组件后如何使酶预期错误
- c# - DateTime.TryParse 似乎正在丢失原始时区信息并转换为服务器时间
- python - 在 Python 中从给定的最大位数和小数位数创建最大可能的十进制数
- java - 将自定义 RequestBody 从 POST 请求发送到 java 中的外部 GET 请求
- python - 使用 Python 处理查询中的 BigQuery 错误
- javascript - 如何刮掉面包屑内部文本并将其用作我的 Google 标记管理器中的变量