2015-03-02 81 views
2

我已經反應鉻擴展安裝,我知道它的工作,因爲它顯示在instagram.com上。不過,我經歷的陣營教程(http://facebook.github.io/react/docs/tutorial.html)和反應選項卡不顯示在我的控制檯窗口這裏是我的所有代碼:反應開發者控制檯不顯示

<!-- index.html --> 
<html> 
    <head> 
    <title>Hello React</title> 
    <script src="http://fb.me/react-0.12.2.js"></script> 
    <script src="http://fb.me/JSXTransformer-0.12.2.js"></script> 
    <script src="http://code.jquery.com/jquery-1.10.0.min.js"></script> 
    </head> 
    <body> 
    <div id="content"></div> 
    <script type="text/jsx"> 
    var data = [ 
     {author: "Derp", text: "this is another comment"}, 
     {author: "Derp", text: "this is a comment"} 
    ]; 

     var CommentBox = React.createClass({ 
     loadCommentsFromServer: function() { 
      $.ajax({ 
      url: this.props.url, 
      dataType: 'json', 
      success: function(data) { 
       this.setState({data: data}); 
      }.bind(this), 
      error: function(xhr, status, err) { 
       console.error(this.props.url, status, err.toString()); 
      }.bind(this) 
      }); 
     }, 
     handleCommentSubmit: function(comment) { 
      $.ajax({ 
      url: this.props.url, 
      dataType: 'json', 
      type: 'POST', 
      data: comment, 
      success: function(data) { 
       this.setState({data: data}); 
      }.bind(this), 
      error: function(xhr, status, err) { 
       console.error(this.props.url, status, err.toString()); 
      }.bind(this) 
      }); 
     }, 
     getInitialState: function() { 
      return {data: []}; 
     }, 
     componentDidMount: function() { 
      this.loadCommentsFromServer(); 
      setInterval(this.loadCommentsFromServer, this.props.pollInterval); 
     } 
     render: function() { 
      return (
      <div className="commentBox"> 
       <h1>Comments</h1> 
       <CommentList data={this.state.data}/> 
       <CommentForm onCommentSubmit={this.handleCommentSubmit}/> 
      </div> 
     ); 
     } 
     }); 

     var CommentList = React.createClass({ 
     render: function() { 
      var comments = this.props.data.map(function (comment){ 
      return (
       <Comment author={comment.author}> 
       {comment.text} 
       </Comment> 
      ) 
      }) 

      return (
      <div className="commentList"> 
       {comments} 
      </div> 
     ); 
     } 
     }); 

     var Comment = React.createClass({ 
     render: function() { 
      return (
      <div className="comment"> 
       <h2 className="commentAuthor"> 
       {this.props.author} 
       </h2> 
       {this.props.children} 
      </div> 
     ); 
     } 
     }) 

     var CommentForm = React.createClass({ 
     handleSubmit: function(e) { 
      e.preventDefault(); 
      var author = this.refs.author.getDOMNode().value.trim(); 
      var text = this.refs.text.getDOMNode().value.trim(); 
      if(!text || !author) { 
      return; 
      } 
      this.props.onCommentSubmit({author: author, text: text}); 
      this.refs.author.getDOMNode().value = ''; 
      this.refs.text.getDomNode().value = ''; 
     }, 
     render: function() { 
      return (
      <div className="commentForm"> 
       <form className="commentForm"> 
       <input type="text" placeholder="your name" ref="something"/> 
       <input type="text" placeholder="say something" ref="someting" /> 
       <input type="submit" value="Post" /> 
       </form> 
      </div> 
     ); 
     } 
     }); 

     React.render(
     <CommentBox url="comments.json" pollInterval={2000}/>, 
     document.getElementById('content') 
    ); 
    </script> 
    </body> 
</html> 

我的控制檯說以下內容:

Download the React DevTools for a better development experience: http://fb.me/react-devtools 

You are using the in-browser JSX transformer. Be sure to precompile your JSX for production - http://facebook.github.io/react/docs/tooling-integration.html#jsx 

Uncaught Error: Parse Error: Line 41: Unexpected identifier 

我在那裏有一個錯誤,但我試圖讓React選項卡暫時顯示並且不太確定如何執行它。

+1

後''在你CommentBox'忘記添加逗號 – Dhiraj 2015-03-02 21:34:11

+0

THX,顯然是錯誤是防止裝載 – Saad 2015-03-02 21:41:16

+1

如果你的反應擴展componentDidMount'方法有一個解決方案,你可以寫在提供的答案框中,然後接受它。 (或刪除問題)。這比編輯單詞「解決」成問題更好,這將問題留在「未答覆」隊列中,永遠是永久性的。 – 2015-04-26 15:33:10

回答

0

這是發生在我身上的其他可能的原因是因爲我沒有沒有全局作出反應的對象,或全局要求能夠要求(「反應」)從全球範圍。
我能夠通過在我的大文件中作出反應來使擴展工作。我敢肯定它會工作同在的WebPack文件:

var React = require('react');