require(‘react’); var Item = React.createClass({ getInitialState: function() { return { count: this.props.initialCount }; },
_increment: function() {
this.setState({ count: this.state.count + 1 });
},
render: function() {
return (
<div onClick={this._increment}>
{this.state.count}
</div>
)
}
}); module.exports = Item;
我想通过一个方法,返回一个字符串,内容是除了“require(‘react’);“和”module.exports = Item;”以外的所有代码。也就是: ‘var Item = React.createClass({’+ ‘getInitialState: function() {’+ ‘return {’+ ‘count: this.props.initialCount’+ ’};’+ ’},’+ ’_increment: function() {’+ ‘this.setState({ count: this.state.count + 1 });’+ ’$.post("/xx", function (doc) {$("#container").text(doc.name)});’+ ’},’+ ‘render: function() {’+ ‘return <div onClick={this._increment}>’+ ’{this.state.count}’+ ’</div>;’+ ’}’+ ’});’ 我该怎么办?
读取文件
var lines=fs.readFileSync(filepath,{encoding:‘utf8’}).split(’/n’); lines.pop(); lines.shift(); console.log(lines);