2016-07-19 38 views
-1

我需要在第二天學習React並從官方教程開始。一切都很好,直到我得到了我的代碼這種狀態下,我得到一個錯誤,我不知道如何繞過它:反應教程 - 無法讀取未定義的屬性'toString'

</head> 
    <body> 
    <div id="content"></div> 
    <!-- script type="text/babel" src="scripts/example.js"></script --> 
    <script type="text/babel"> 
     var CommentBox = React.createClass({ 
      render: function() { 
      return (
       <div className = "commentBox"> 
       <h1>Comments</h1> 
       <CommentList /> 
       <CommentForm /> 
       <Comment /> 
       </div> 
      ); 
     } 
     }); 

      var CommentList = React.createClass({ 
      render: function() { 
       return (
       <div className = "commentList"> 
        <Comment author = "Michael Johnson">This is one 
         comment</Comment> 
        <Comment author = "Daniel Kammer">This is the 'second' 
         comment</Comment> 
        </div> 
       ); 
      } 
      }); 

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

      var Comment = React.createClass({ 
      var md = new Remarkable(); 
      render: function() { 
      return (
      <div className = "comment"> 
       <h2 className = "commentAuthor"> 
       {this.props.author} 
       </h2> 
      *** ERROR IS GENERATED BY THE BELOW STATEMENT *** 
       {md.render(this.props.children.toString())} 
      </div> 
      ); 
     } 
     }); 

本教程的其餘部分繼續向前的md.render聲明 - 所以我需要了解如何解決此錯誤

+0

什麼是在控制檯「this.props.children」的輸出?什麼是Remarkable()?請提供更多信息和鏈接。 –

回答

0

這可能是<Comment />組件中的ComentBox組件造成的。都需要Comment部件的正常工作子組件,但關閉標籤沒有兒童(this.prop.childrens爲null或undefined =>方法toString不宣)

相關問題