首页 > Web开发 > 详细

29.React ajax中setState

时间:2017-08-04 13:40:33      阅读:189      评论:0      收藏:0      [点我收藏+]
$.ajax({
          url: url,
          type: "POST",
          timeout : 6000000, //超时时间设置,单位毫秒
          data: JSON.stringify(json),
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success:function(d){
                    
            if(d.result==0){
                        
                 this.setState({
                  commission:d.data.commission
                 })
              }
                    
          }.bind(this)
    })

bind(this)

有时候在元素上绑定事件,像下面这样,看起来很正常,但是会报一些未定义的错误

<div onClick={this.hanldeClick}></div>

你可能需要这么操作

getInitialState: function() {
    this.handleClick = this.handle.bind(this)
    return {};
},    
constructor(props){
  super(props)
  this.handleClick = this.handleClick.bind(this)     
}

 

29.React ajax中setState

原文:http://www.cnblogs.com/famLiu/p/7284382.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!