CNode

如何将一段Module的内容转字符串

问答
Uudctfx发布于12 年前最后回复12 年前2 回复4367 浏览0 收藏

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 '+ '{this.state.count}'+ ';'+ '}'+ '});' 我该怎么办?

查看回复

回复 (2)

I
ierask#1·12 年前

读取文件

D
dayuoba#2·12 年前

var lines=fs.readFileSync(filepath,{encoding:'utf8'}).split('/n'); lines.pop(); lines.shift(); console.log(lines);

参与回复
登录后即可参与回复。登录