var FancyCheckbox = React.createClass({
render: function() {
var { checked, ...other } = this.props;
var fancyClass = checked ? 'FancyChecked' : 'FancyUnchecked';
return (
<div {...other} className={fancyClass} /> //***这里提示有错误***
);
}
});
React.render(
<FancyCheckbox checked={true} onClick={console.log.bind(console)}>
Hello world!
</FancyCheckbox>,
document.getElementById('example')
);
我用chome的console里看到如上提示有错误,手册...other为什么不能用
var { checked, ...other } = this.props;
这一个语句是用到了 es6 解构语法,需要配合 babel 编译js才可以运行。
参考 http://es6.ruanyifeng.com/#docs/destructuring
var { checked, ...other } = this.props;
在这句下面console.log(...ohter)
,看有没有值。
这句话就不对吧。还有用es6 就不要用var 用let和const来声明变量
...
是 ES6 新增的语法,要配合 babel 之类的预编译器编译为浏览器支持的语法(如 ES5)才能运行