javascript - How to insert json data in React js? - Stack Overflow

I have a following list of data's. I need to insert my template. How to achieve this one with Reac

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
Add a ment  | 

3 Answers 3

Reset to default 2

Here 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

相关推荐

  • javascript - How to insert json data in React js? - Stack Overflow

    I have a following list of data's. I need to insert my template. How to achieve this one with Reac

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信