I have a following list of data's. I need to insert my template. How to achieve this one with React js.
[
{
product:"one",
quantiy:2
},
{
product:"two",
quantiy:4
},
{
product:"three",
quantiy:3
}
]
I have a following list of data's. I need to insert my template. How to achieve this one with React js.
[
{
product:"one",
quantiy:2
},
{
product:"two",
quantiy:4
},
{
product:"three",
quantiy:3
}
]
Share
Improve this question
asked Nov 30, 2015 at 10:44
SathyaSathya
1,7343 gold badges38 silver badges59 bronze badges
3 Answers
Reset to default 2Here is a working jsbin example http://jsbin./ziqelujevi/2/edit?html,js,output
Update: Display all the items http://jsbin./cibuhogudu/1/edit?html,js,console,output
Here is working code: http://jsbin./wafemul/edit?html,js,output
var data = [
{
product:"one",
quantiy:2
},
{
product:"two",
quantiy:4
},
{
product:"three",
quantiy:3
}
];
class App extends React.Component {
constructor(props){
super(props);
this.state= {
data: data
}
}
render() {
return (
<div>
<h1>Heading</h1>
<div>{this.state.data.map( item => (
<li>{item.product}</li>
))}
</div>
</div>
);
}
};
ReactDOM.render(
<App />,
document.getElementById('box')
);
Pass it as a propety to the ponent and you can access it using this.props.data in the render method.
Ex:
var data = [....]
<SampleComponent data={data} />,
Or use state to pass data
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744893198a4599538.html
评论列表(0条)