[英]No items iterated in array jsx
I'm going insane over this problem. 我对这个问题发疯了。 The map iteration does not iterate over the items.
地图迭代不会遍历所有项目。 It render the {this.props.data.length} correct.
它使{this.props.data.length}正确。 I get '1' in this case.
在这种情况下,我得到“ 1”。 No errors or anything in the console.
控制台中没有错误或任何错误。 The console.log prints the object and it contains all the data.
console.log打印对象,它包含所有数据。
var Component = React.createClass({
render: function(){
var data = this.props.data;
if(data == null) {
return (<p>...</p>)
}
if(data.information == null) {
data.information = {informations: []};
}
if(data.technicalData == null){
data.technicalData=[];
}
if(data.suppliers == null) {
data.suppliers = [];
} else {
console.log(data.suppliers);
}
return (
<div className="row">
<h1 className="page-header">{data.name}</h1>
<div className="col-md-3">
<Information info={data.information.informations}/>
</div>
<div className="col-md-3">
<TechInfo tech={data.technicalData}/>
</div>
<div className="col-md-3">
<Supplier data={data.suppliers}/>
</div>
</div>
);
}
});
var Supplier = React.createClass({
render: function() {
return (
<div className="row">
<h2>Supplier</h2>
Number of suppliers: {this.props.data.length}
{this.props.data.map(function(item, i){
<p>Supplier index: {i}</p>
})}
</div>
)
}
});
suppliers: [
{ name: "elfa",
attributes: [
{ key: "artnr",
value: "58-578-83"
},
{ key: "url",
value: "https://www.elfa.se"
}
]
}
You're not returning anything from inside the map
. 您不会从
map
内部返回任何内容。 Add a return
statement: 添加一个
return
语句:
{this.props.data.map(function(item, i){
return <p>Supplier index: {i}</p>;
})}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.