admin管理员组文章数量:1386933
I have an array of objects. And I can't figure out how do I create multiple card decks with 3 cards in each one, as on the image:
An example is below:
import { Card, Button, ... CardBlock } from 'reactstrap';
export default const Example = (props) => {
return (<div>
<CardDeck>
<Card>
<CardImg top width="100%" src="https://..." />
<CardBlock>
<CardTitle>{data.title}</CardTitle>
<CardSubtitle>{data.subtitle}/CardSubtitle>
<CardText>{data.text}</CardText>
<Button>Button</Button>
</CardBlock>
</Card>
<Card>
...
</Card>
<Card>
...
</Card>
</CardDeck>
<CardDeck>
...
</CardDeck>
...
</div>
);
};
I have an array of objects. And I can't figure out how do I create multiple card decks with 3 cards in each one, as on the image:
An example is below:
import { Card, Button, ... CardBlock } from 'reactstrap';
export default const Example = (props) => {
return (<div>
<CardDeck>
<Card>
<CardImg top width="100%" src="https://..." />
<CardBlock>
<CardTitle>{data.title}</CardTitle>
<CardSubtitle>{data.subtitle}/CardSubtitle>
<CardText>{data.text}</CardText>
<Button>Button</Button>
</CardBlock>
</Card>
<Card>
...
</Card>
<Card>
...
</Card>
</CardDeck>
<CardDeck>
...
</CardDeck>
...
</div>
);
};
Share
Improve this question
asked Jul 1, 2017 at 21:41
Taras YaremkivTaras Yaremkiv
3,6008 gold badges33 silver badges56 bronze badges
1
- 1 So what doesn't work as expected in your code? Can you ask a specific question? – trixn Commented Jul 1, 2017 at 22:04
1 Answer
Reset to default 4If your question is about how to iterate over your array then you can use Array.prototype.map() for it.
An example from the react docs with map()
call using an arrow function:
By saving the ponents in a temporary variable:
function NumberList(props) {
const numbers = props.numbers;
const listItems = numbers.map((number) =>
<ListItem key={number.toString()}
value={number} />
);
return (
<ul>
{listItems}
</ul>
);
}
By using map()
inline:
function NumberList(props) {
const numbers = props.numbers;
return (
<ul>
{numbers.map((number) =>
<ListItem key={number.toString()}
value={number} />
)}
</ul>
);
}
EDIT:
Do not render multiple <CardDeck>
ponents. Instead adapt your css so that a <Card>
will wrap into the next row when there are more that three. Then you only have to map the data inside your array once and not for every <CardDeck>
again.
本文标签: javascriptNice way in React to Map an array data to Card DecksStack Overflow
版权声明:本文标题:javascript - Nice way in React to Map an array data to Card Decks - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744564596a2612970.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论