在className react.js中调用函数

Chi*_*ipe 11 javascript reactjs

如何调用该函数getClassclassName这个例子里面?我写出来的方式似乎没有打电话getClass.

var CreateList = React.createClass({
    getClass: function() {
        //some code to return className
    },
    render: function() {
        return(
            <div className{this.getClass}>Example</div>
        );
    }
});
Run Code Online (Sandbox Code Playgroud)

pse*_*ble 12

您正在引用getClass()函数的实例而不是调用函数.尝试调整它如下:

render: function() {
    return(
        <div className={this.getClass()}>Example</div>
    );
}
Run Code Online (Sandbox Code Playgroud)