Reactjs TypeError:\u此2未定义
我一直在尝试使用单选按钮的价值。它们在物化模式中渲染。我绑定了一个函数Reactjs TypeError:\u此2未定义,reactjs,Reactjs,我一直在尝试使用单选按钮的价值。它们在物化模式中渲染。我绑定了一个函数rendermarkoption。但每当我点击单选按钮时,它就会显示TypeError:_this2未定义 selectChangeHandler(e){ // console.log(e.target.name,e.target.value) if (typeof e === 'string' || e instanceof String){ // alert(e) } el
rendermarkoption
。但每当我点击单选按钮时,它就会显示TypeError:_this2未定义
selectChangeHandler(e){
// console.log(e.target.name,e.target.value)
if (typeof e === 'string' || e instanceof String){
// alert(e)
}
else{
const input_name = e.target.name;
const input_value = e.target.value;
if(!this.isBlank(input_value,'Field '+input_name+' is required'))
{
return false;
}
if(!this.isPreviousStateSame(input_name,input_value,this.props.lead)){
if(input_name=='lead_status')
{
this.props.updateLeadProps({name: input_name,value:input_value},'UPDATE_LEAD');
{/*if(this.props.remark.text=='')
{
alert('')
return false;
}*/}
console.log('presalesid',this.props.lead)
if(this.next_followup_datetime == undefined) this.next_followup_datetime = this.props.lead.initial_score_timestamp;
let pre_sales_ids = !this.props.isBulkProcessing.is_bulk_process? [this.props.lead.id] : this.props.isBulkProcessing.ids;
this.props.postFetch(
urls.post_leads_remark,
{
pre_sales_ids:pre_sales_ids,
lead_status:this.props.remark.type ,
initial_score_timestamp:this.next_followup_datetime,
remark:this.props.remark.text
},
'POST_LEADS_REMARK'
);
return false;
}
if(input_name=='options'){
alert(input_value)
this.setState({chosen_remark:input_value})
}
if(this.props.isBulkProcessing.is_bulk_process)
{
this.props.postFetch(
urls.update_leads,
{
pre_sales_ids : this.props.isBulkProcessing.ids,
name:input_name,
value:input_value
},
'UPDATE_LEAD'
);
//console.log('bulk processin g',pre_sales_ids);
}
else{
this.props.postFetch(
urls.LEAD_BASIC_INFO_UPDATE,
{
pre_sales_id:this.props.lead.id,
name:input_name,
value:input_value
},
'UPDATE_LEAD'
);
}
}
}
}
renderRemarkOption(data) {
let template =[];
this.props.controllSelectData.remarks_content[data].forEach(function(item,index){
template.push(<p key={index}><input className="with-gap" name="options" type="radio" id={index} onChange={(e)=>this.selectChangeHandler(e)}/><label htmlFor={index} key={index} >{item}</label></p>)
})
this.setState({remark_content:template},function(){
$(`#${data}_modal`).modal('open');
})
return this.state.remark_content
}
render() {
return(
<div className="col s12">
<form >
{
this.state['remark_content']
}
<div className="col s12 right remark-field">
<Input type="textarea" name="remark"/>
</div>
<a className="waves-effect waves-light btn submit-button" type="submit" onClick={this.selectChangeHandler('not_reachable')}>Submit</a>
</form>
</div>
)
}
selectChangeHandler(e){
//日志(e.target.name,e.target.value)
if(typeof e=='string'| | e string实例){
//警报(e)
}
否则{
const input_name=e.target.name;
常量输入值=e.target.value;
如果(!this.isBlank(输入值,'Field'+输入名称+'是必需的'))
{
返回false;
}
如果(!this.isPreviousState相同(输入\名称、输入\值、this.props.lead)){
如果(输入_名称=='lead_status')
{
this.props.updateLeadProps({name:input_name,value:input_value},'UPDATE_LEAD');
{/*if(this.props.remark.text='')
{
警报(“”)
返回false;
}*/}
console.log('presalesid',this.props.lead)
如果(this.next\u followup\u datetime==未定义)this.next\u followup\u datetime=this.props.lead.initial\u score\u timestamp;
让售前\u id=!this.props.isBulkProcessing.is\u bulk\u流程?[this.props.lead.id]:this.props.isBulkProcessing.ids;
这个是.props.postFetch(
url.post_leads_备注,
{
售前识别码:售前识别码,
lead_状态:this.props.remark.type,
初始评分时间戳:this.next\u followup\u datetime,
备注:this.props.remark.text
},
“发布线索和评论”
);
返回false;
}
如果(输入_name=='options'){
警报(输入值)
this.setState({selected_remark:input_value})
}
if(this.props.isBulkProcessing.is\u bulk\u进程)
{
这个是.props.postFetch(
url.update_线索,
{
售前标识:this.props.isBulkProcessing.ids,
名称:输入_名称,
值:输入值
},
“更新线索”
);
//console.log(“批量处理”,售前ID);
}
否则{
这个是.props.postFetch(
url.LEAD\u基本信息\u更新,
{
售前标识:this.props.lead.id,
名称:输入_名称,
值:输入值
},
“更新线索”
);
}
}
}
}
RenderMarkOption(数据){
让模板=[];
this.props.controllSelectData.comments\u content[data].forEach(函数(项,索引){
push(this.selectChangeHandler(e)}/>{item}
)
})
this.setState({remark_content:template},function()){
$(`${data}{u model`).model('open');
})
返回this.state.remark\u内容
}
render(){
返回(
{
此.说明[“备注内容”]
}
提交
)
}
看起来您没有将回调传递给onClick
属性,而是在执行函数:
<a className="waves-effect waves-light btn submit-button" type="submit" onClick={this.selectChangeHandler('not_reachable')}>Submit</a>
提交
应该是
<a className="waves-effect waves-light btn submit-button" type="submit" onClick={() => this.selectChangeHandler('not_reachable')}>Submit</a>
this.selectChangeHandler('not_reachable')}>Submit
真的不知道你想做什么,你能提供一个jsfidle吗?你的onClick=
函数名前面有这么多空格吗?您能正确格式化插入的代码吗?您必须显示更多代码()。特别是绑定函数的方式。您还可以在onClick中调用名为selectChangeHandler
的方法,但您只显示名为rendermarkoption
的方法,因此很难判断代码应该做什么。rendermarkoption用于创建单选按钮列表。然后将这些单选按钮按到一个状态,该状态在模式中用于表示单选按钮列表。我想从模式中显示的列表中选择值单选按钮。因此,在单选按钮标记中添加onClick似乎是合适的。\u react2.default.createElement('input',{className:'with gap',name:'options',type:'radio',id:index,onChange:function onChange(e){return this2.selectChangeHandler(e);})
单击控制台中的错误时会显示此信息。