Answer the question
In order to leave comments, you need to log in
How to get 1 value from an array in React?
Here I have values in orders array, there are products, username and order id
var GoodsTable = React.createClass({
getInitialState: function(){return{goods: []};
},
render: function(){
var itemNodes = this.state.goods.map(function(tableItem){
return (<GoodsRow item={tableItem}/>);
});
var GoodsRow = React.createClass({
render: function(){
var row = (
<tr>
<td>{this.props.item.Good_Name}</td>
<td>{this.props.item.Login}</td>
</tr>);
return row;
}
});
Answer the question
In order to leave comments, you need to log in
It's not very clear what you mean by
get
I'll do my part. I will be based on the answer of Alexey Zuev :
1. Make a separate component for the row with the product (GoodRow) and the row with the user's goods (UserGoodsRow). Still different things.
2. Add a key property to all dynamic child components
3. Never capitalize object fields. Fi. Yes, and CamelCase is preferable to SnakeCase
Result -> jsfiddle.net/yuvuyrhv/11
4. How do you feel about ES6? You still need babel!
jsfiddle.net/yuvuyrhv/13
5. Specify propTypes
And finally, I will say that the logic of partitioning products by users is REQUIREDmove to a separate layer (either in business ... or, at worst, in some controller-view like UserGoodsPage)
Final result -> jsfiddle.net/yuvuyrhv/14
PS I also recommend using one of the tools that make FP easier - be it lodash, underscore or ramdajs
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question