2015-12-05 69 views
2

問題:我是working this tutorial瞭解React.js。我已經將showdown.js文件正確添加到項目中,並證明它在客戶端瀏覽器中作爲腳本文件加載。當頁面加載時,我看着控制檯顯示標題中列出的錯誤。Uncaught ReferenceError:攤牌沒有定義,ReactJS.NET

環境: 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') 
); 

證明showdown.js文件被髮送到客戶端瀏覽器的Chrome:

ShowdownLoaded

證明的語法是正確的JSX文件

這裏拋出異常的代碼行是:

var converter = new Showdown.converter(); 

ShowDownConvertor

問題 我如何獲得的新實例Showdown.convertor?

+1

您是否在您的索引文件中的'Tutorial.jsx'之後包含'showdown.js'腳本? –

+0

@JanKlimo是的,這是問題...我需要後加載文件。謝謝! –

+1

甜!沒問題。 –

回答

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文件之前。

相關問題