admin管理员组文章数量:1297042
I want to send element's index on click in function. Because I should change data for every element and get it from array.
How can I get key in MainBlock
from List
? Is it possible? Or I do something wrong?
I'm very new in React and do many mistakes.
var MainBlock = React.createClass({
Click: function() {
// I need to get element KEY
// var data = array[key]
},
render: function() {
return (
<List Click={this.props.Click.bind(null, this)}>
);
}
});
var List = React.createClass({
render: function() {
var ItemNodes = this.props.data.map(function(step, index) {
return (
<Item className="class" Click={this.props.Click.bind(null, this)} key={index} />
);
}.bind(this));
return (
<ul>
{ItemNodes}
</ul>
);
}
});
var StepWindow = React.createClass({
render: function() {
return (
<li onClick={this.props.Click}>
yo!
</li>
);
}
});
Thank you for your help.
I want to send element's index on click in function. Because I should change data for every element and get it from array.
How can I get key in MainBlock
from List
? Is it possible? Or I do something wrong?
I'm very new in React and do many mistakes.
var MainBlock = React.createClass({
Click: function() {
// I need to get element KEY
// var data = array[key]
},
render: function() {
return (
<List Click={this.props.Click.bind(null, this)}>
);
}
});
var List = React.createClass({
render: function() {
var ItemNodes = this.props.data.map(function(step, index) {
return (
<Item className="class" Click={this.props.Click.bind(null, this)} key={index} />
);
}.bind(this));
return (
<ul>
{ItemNodes}
</ul>
);
}
});
var StepWindow = React.createClass({
render: function() {
return (
<li onClick={this.props.Click}>
yo!
</li>
);
}
});
Thank you for your help.
Share edited Feb 6, 2015 at 3:27 AndryName asked Feb 6, 2015 at 3:13 AndryNameAndryName 6522 gold badges7 silver badges12 bronze badges1 Answer
Reset to default 7Try this:
Click={this.props.Click.bind(this, index)}
Click: function(idx, e){
}
check out the boundClick in the docs example http://facebook.github.io/react/tips/expose-ponent-functions.html
edit I've edited this to show that the parameters passed to the Click function are in the different order. It was e, idx and should be idx, e.
本文标签: javascriptReactJS send key(index) on clickStack Overflow
版权声明:本文标题:javascript - ReactJS send key(index) on click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741646097a2390192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论