React里的事件参数传递和传统的JS参数有些不一样,需要通过bind方法来绑定参数,第一个参数指向this,第二个参数开始才是事件函数接收到的参数
<button onClick={this.handleClick.bind(this, props0, props1, ...}></button>
handleClick(porps0, props1, ..., event) {
// your code here
}
showDetail:function(url){
window.open(url);
},
render:function(){
var o = this;
var list = this.props.date.map(function(c){
return(
<li onClick={o.showDetail.bind(c,c.txtUrl)}>
<h1><span className="am-badge am-badge-success am-radius ">{c.txtSource}</span>{c.title}</h1>
<span className="price am-badge am-badge-warning am-radius ">{c.numPrice}</span>
</li>
);
});
return(
<div id="result">
<ul className="am-list">
{list}
</ul>
</div>
);
}