未捕获的ReferenceError:未定义Showdown,ReactJS.NET

时间:2015-12-05 04:47:37

标签: javascript reactjs.net

问题:working this tutorial了解React.js。我已将showdown.js文件正确添加到项目中,并证明它已作为脚本文件加载到客户端浏览器中。当页面加载并且我查看控制台时,它会显示标题中列出的错误。

环境: MVC 4/5,Reactjs.NET

JSX文件看起来像这样:

var Comment = React.createClass({
  render: function() {
    var converter = new Showdown.converter(); <-- Error is here
    return (
      <div className="comment">
        <h2 className="commentAuthor">
            {this.props.author}
        </h2>
          {converter.makeHtml(this.props.children.toString())}
      </div>
    );
  }
});
var CommentList = React.createClass({
    render: function () {
        return (
          <div className="commentList">
            <Comment author="Daniel Lo Nigro">Hello ReactJS.NET World!</Comment>
            <Comment author="Pete Hunt">This is one comment</Comment>
            <Comment author="Jordan Walke">This is *another* comment</Comment>

          </div>
      );
    }
});

var CommentForm = React.createClass({
    render: function () {
        return (
          <div className="commentForm">
              Hello, world! I am a CommentForm.
          </div>
      );
    }
});


var CommentBox = React.createClass({
    render: function () {
        return (
      <div className="commentBox">
        <h1>Comments</h1>
        <CommentList />
        <CommentForm />
      </div>
    );
    }
});
ReactDOM.render(
  <CommentBox />,
  document.getElementById('content')
);

将showof showdown.js文件发送到客户端Chrome浏览器:

ShowdownLoaded

证明JSX文件中的语法是正确的

抛出异常的代码行是:

var converter = new Showdown.converter();

ShowDownConvertor

问题 如何获得Showdown.convertor的新实例?

1 个答案:

答案 0 :(得分:1)

Jan上面的建议是正确的。这就解决了这个问题:

<body>
  <div id="content"></div>
  <script src="https://fb.me/react-0.14.0.min.js"></script>
  <script src="https://fb.me/react-dom-0.14.0.min.js"></script>
  <script src="@Url.Content(" ~/Scripts/showdown.min.js ")"></script>
  <script src="@Url.Content(" ~/Scripts/Tutorial.jsx ")"></script>
</body>

请注意,showdown.js必须位于jsx文件之前。