Ban*_*hee 8 javascript reactjs react-jsx reactjs.net
我从reactJS.NET得到这个警告
bind():您正在将组件方法绑定到组件.React会以高性能方式自动为您执行此操作,因此您可以安全地删除此调用.见LikeCon
组件看起来像这样
var LikeCon = React.createClass({
    handleClick: function() {
            var data = new FormData();
            var like = !this.state.like;
            var likeCounter = this.state.likeCount;
            data.append("catgoryType", this.state.categoryKey);
            data.append("objectId", this.state.objectId);
            data.append("like", like);
            if(like)
                likeCounter++;
            else
                likeCounter--;
            this.setState({ like: like, likeCount: likeCounter, userId: this.state.userId, categoryKey: this.state.categoryKey, objectId: this.state.objectId});
            var xhr = new XMLHttpRequest();
            xhr.open("post", "http://localhost:2215/Home/SetLike", true);
            xhr.onload = function() {
        };
        xhr.send(data);
    },
    getInitialState: function() {
        return { like: this.props.initialLike, likeCount: this.props.initialLikeCount, userId: this.props.userId, categoryKey: this.props.categoryKey, objectId: this.props.objectId  };
    },
    render(){
        return this.renderLikeButton()
    },
    renderLikeButton(){
        return (
                content =  
                <div className="likeCon">
                    <div className={this.state.like==true ? "likeButConAct" : "likeButCon"}>
                        <div className="likeB" title={this.state.like==true ? "Unlike" : "Like"} onClick={this.handleClick.bind(this)} >
                             
                        </div>
                        { this.state.likeCount > 0 ? <div className="likeCount">{this.state.likeCount}</div>: null}
                    </div>
                </div>
            );
    }
})
我在调用方法handleClick时使用了一个bind,如果我删除它,我会得到另一个异常?那么我该怎样做呢?
| 归档时间: | 
 | 
| 查看次数: | 7294 次 | 
| 最近记录: |