admin管理员组文章数量:1405388
I am starting to get involved in ReactJS, I am trying to pass to my tag a JSON object so then I can show it in the UI but it keeps saying that element is not found. Any help on this? Or why the props object is not having the JSON object? Thanks in advance
var CommentBox = React.createClass({
render: function() {
return (
<div className="img-container">
<img src="{this.props.placementImage}" />
</div>
);
}
});
var MP = [
{
id: "MP1001",
placementImage: ".png",
dts: "forever",
dte: "forever",
status: "",
isDefault: false
}
];
ReactDOM.render(
<CommentBox mp={MP}/>,
document.getElementById('content')
);
I am starting to get involved in ReactJS, I am trying to pass to my tag a JSON object so then I can show it in the UI but it keeps saying that element is not found. Any help on this? Or why the props object is not having the JSON object? Thanks in advance
var CommentBox = React.createClass({
render: function() {
return (
<div className="img-container">
<img src="{this.props.placementImage}" />
</div>
);
}
});
var MP = [
{
id: "MP1001",
placementImage: "https://www.aexp-static./intl/uk/rwd/images/UKHP_CM_promo_3.png",
dts: "forever",
dte: "forever",
status: "",
isDefault: false
}
];
ReactDOM.render(
<CommentBox mp={MP}/>,
document.getElementById('content')
);
Share
Improve this question
asked Jan 20, 2016 at 20:44
JorgeJorge
431 silver badge9 bronze badges
2 Answers
Reset to default 3A couple things:
You're passing an array as the
mp
prop, but then attempting to access it like an object.You need to remove the quotes from the
<img>
src attribute:You need to access the actual
mp
prop
For reference, I've created a JSBin example from your code that fixes these issues: http://jsbin./bohoqa/edit?html,js,output
var CommentBox = React.createClass({
render: function() {
return (
<div className="img-container">
<img src={this.props.mp.placementImage} />
</div>
);
}
});
var MP = [
{
id: "MP1001",
placementImage: "https://www.aexp-static./intl/uk/rwd/images/UKHP_CM_promo_3.png",
dts: "forever",
dte: "forever",
status: "",
isDefault: false
}
];
ReactDOM.render(
<CommentBox mp={MP[0]}/>,
document.getElementById('content')
);
change
<img src="{this.props.placementImage}" />
to
<img src={this.props.mp[index].placementImage} />
You have to pass them as objects {} not "{}"
edit: I did not notice it was an array
本文标签: javascriptTrying to pass JSON object REACTJS not workingStack Overflow
版权声明:本文标题:javascript - Trying to pass JSON object REACTJS not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744888192a2630612.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论