我有一个组件,接收一个记录列表作为prop。我尝试在onClick事件中添加一个函数,但是设置为执行点击事件的代码会在组件加载时立即触发。在这种情况下,我指的是processM函数。我是ReactJS的新手,希望得到任何帮助。
var TempJobTaskActions = React.createClass({
processM: function(url){
console.log('in processMove: ', url);
$.ajax({
type: 'GET',
url: url,
success: function(data){
}
});
},
render: function(){
var action = null;
var downUrl = '../MoveDown?id='+this.props.tid;
var upUrl = '../MoveUp?id='+this.props.tid;
if(this.props.position == "solo"){
action = (<span></span>);
}
if(this.props.position == "first"){
action = (<span><a className='cdc-link cdc-icon glyphicon glyphicon-arrow-down'
href='#' onClick={this.processM(downUrl)} title='Move Down'></a></span>);
}
if(this.props.position == "last"){
action = (<span><a className='cdc-link cdc-icon glyphicon glyphicon-arrow-up'
href='#' onClick={this.processM(upUrl)} title='Move Up'></a></span>);
}
if(this.props.position == "middle"){
action = (
<div>
<span><a className='cdc-link cdc-icon glyphicon glyphicon-arrow-up'
href='#' onClick={this.processM(upUrl)} title='Move Up'></a></span>
<span><a className='cdc-link cdc-icon glyphicon glyphicon-arrow-down'
href='#' onClick={this.processM(downUrl)} title='Move Down'></a></span>
</div>
);
}
return (
<div>{action}</div>
);
}
});