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
 }
]

3 Answers 3

2

Here is a working jsbin example http://jsbin.com/ziqelujevi/2/edit?html,js,output

Update: Display all the items http://jsbin.com/cibuhogudu/1/edit?html,js,console,output

Sign up to request clarification or add additional context in comments.

3 Comments

How to display all data's?
Thank u so mach @andrei. This is what i want. If it is multi dimensional array means, how the code structure will be?
@Sathya depends on what that data means. But essentially it will be the same only that the map function will get more complicated (now an element in the .map function means a row so more processing will be in place). Continuing on this idea maybe you want to have something where in the map function you do return <ChildComponent data={el}/> so you pass along the rendering to a child.
1

Here is working code: http://jsbin.com/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')
);

Comments

0

Pass it as a propety to the component 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

2 Comments

Hi @Bijeshp009. Can u give me the fiddle example?
have a look at this it is a straight forward approach : facebook.github.io/react/docs/tutorial.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.