【发布时间】:2019-12-27 21:09:37
【问题描述】:
我一直在关注一个教程系列,并试图推断我迄今为止所做的事情。
我已查询内容以返回其中一种数据类型是 productFeatures 数组的产品详细信息。我试图将它映射到一个列表,并希望它能够迭代出几个 li。但是,我最终得到了一个包含所有条目的 li。谁能帮我理解我在这里误解了什么?
这是我在产品特性组件中的尝试
import React from 'react'
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
import './spec.css'
const Spec = ({data}) =>(
<div>
<Tabs>
<TabList>
<Tab>Key Features</Tab>
<Tab>Product Documents</Tab>
</TabList>
<TabPanel>
<ul className="spec_list">
{data.allContentfulProductPage.edges.map(edge =>(
<li className="spec_list__item">{edge.node.productFeatures}</li>
))}
</ul>
</TabPanel>
<TabPanel>
<h2>Any content 2</h2>
</TabPanel>
</Tabs>
</div>
)
export default Spec
这里是graphql查询返回
{
"data": {
"allContentfulProductPage": {
"edges": [
{
"node": {
"productTitle": "HD Pro Projector M220",
"productPrice": 299,
"productDescription": {
"productDescription": "Designed for use with iPhone*, iPad*, MacBook, and Apple TV, the Miroir HD Projector M220 delivers HD-quality projection for streaming, entertainment, or presentation purposes. Even better, it's small enough to fit in your briefcase or bag. The projector uses a long-lasting LED light source and is built with Texas Instrument's DLP technology, which provides a cinema-quality movie experience.\n"
},
"productFeatures": [
"Texas Instruments DLP Technology",
"1280 x 720 (720p) native resolution",
"1080p maximum input resolution",
"Auto focus with vertical keystone",
"HDMI input",
"Viewable screen size from 20 to 100 inches",
"Built-in lithium-ion battery",
"Two hours of projecting time",
"Two built-in 2-watt speakers; audio out jack (3.5mm)"
],
"productImage": [
{
"file": {
"url": "//images.ctfassets.net/2nhrtgh52wv0/7u8biIRohlsl0OFKBWZ0ti/1dabcec4edd13dee708107929ec8e505/product-shot.jpg"
}
},
{
"file": {
"url": "//images.ctfassets.net/2nhrtgh52wv0/7u8biIRohlsl0OFKBWZ0ti/1dabcec4edd13dee708107929ec8e505/product-shot.jpg"
}
}
],
"productSceneImage": {
"file": {
"url": "//images.ctfassets.net/2nhrtgh52wv0/6AzIFw9pZDsRtH1JI3A9XR/80ca785ffc60310690e337f7f936a74f/front-room-scene.jpg"
}
}
}
}
]
}
}
}
这里是graphql查询返回
export const query = graphql`
query ProductQuery {
allContentfulProductPage{
edges{
node{
productTitle
productPrice
productFeatures
productDescription {
productDescription
}
}
}
}
}
`
【问题讨论】:
标签: reactjs graphql gatsby contentful