简体   繁体   English

反应组件渲染但在Rails应用程序的页面上不可见

[英]react component rendering but not visible on page within rails app

I am putting a react-js-jsx component within a view of a rails application. 我将react-js-jsx组件放入Rails应用程序视图中。 When I do inspect element I see the component's html tags in the console but I do not see any visible trace of this component on the page. 当我检查元素时,我在控制台中看到了该组件的html标签,但是在页面上没有看到该组件的任何可见痕迹。 The html tags are below: html标记如下:

 <div id="notebook"><div data-reactid=".1">
   <ul class="dropdown-menu" id="friend-menu" data-reactid=".1.0">    
    <li data-reactid=".1.0.0"><a data-reactid=".1.0.0.0">where am I?</a></li><li data-reactid=".1.0.1"><a data-reactid=".1.0.1.0">who  am I?</a></li>
    <li data-reactid=".1.0.2"><a data-reactid=".1.0.2.0">where do I need to be?</a></li>
    <li data-reactid=".1.0.3"><a data-reactid=".1.0.3.0">what is the meaning of life?</a></li>
  </ul>
 </div>
</div>

I have tested on multiple browsers and I get the same results in that the html tags of the component are not visible. 我已经在多种浏览器上进行了测试,但得到的结果相同,因为该组件的html标记不可见。

The javascript component code is listed here: 此处列出了javascript组件代码:

var Session = React.createClass({

  // handleSubmitAccept: function(e) {
  //   e.preventDefault();
  //   this.props.onSubmitAccept();
  // },
  // handleSubmitDecline: function(e) {
  //   e.preventDefault();
  //   this.props.onSubmitDecline();
  // },
  render: function () {
    return (
        <li>
          <a>{this.props.answer.questionContent}</a>
        </li>
      )
  }

 });



var Sessions = React.createClass({


  getInitialState: function() {
    return {
      answers: [
        // {id:1, url:"", name:"test user", friendStatus: false},
        // {id:2, url:"", name:"test user 2", friendStatus: true}
      ]
    };
  },

  componentDidMount: function() {
    $.get(this.props.source, function(data) {
      this.setState({answers: data.currentUser.answers});
    }.bind(this));

  },

  render: function() {
    var self = this;

    return(
      <ul className="dropdown-menu" id="friend-menu">
        {this.state.answers.map(function (answer) {
          return <Session answer={answer} />
        })}
      </ul>
    );
  }
});


var NoteBook = React.createClass({

  render: function() {
    return (
      <div  >
        <Sessions source="/users/1/answers"/>
      </div>
    );
  }
});

React.render(<NoteBook />,  document.getElementById('notebook'));

The view in which the html tags are rendered (but not visible) is here: 呈现html标签的视图(但不可见)在这里:

<h1>Answers#show</h1>
<p>Find me in app/views/answers/show.html.erb</p>
<div id="notebook"></div>

The layouts/application.html.erb code is this: layouts / application.html.erb代码是这样的:

<!DOCTYPE html>
<html>
<head>
  <title>GlobeTrotters</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>

  <!--
  <%= javascript_include_tag :defaults, "http://localhost:9292/faye.js" %>
   -->

  <%= csrf_meta_tags %>
</head>
<body>
  <script src="http://d3js.org/queue.v1.min.js"></script>
  <script src="http://d3js.org/topojson.v0.min.js"></script>
   <div class="container">

        <ul class="nav nav-tabs">
          <% if show_menu_policy? %>
            <li id="FriendBox" style="margin-top:12px"></li>
          <% end %>
        <!-- component -->

        <li><%= link_to "Globe Trotter's", welcome_index_path %></li>
        <li><%= link_to "About", welcome_about_path %></li>
        <%if current_user%>
          <li id="friend_request"><span class= "glyphicon glyphicon-user" style="margin-top:14px"> </span></li>
        <%end%>
         <%if current_user && current_user.role =="captain" && TeamRelationship.where(receiver_team_id: current_user.team_id ).first%>
               <li><%= link_to "Friend Requested!",team_relationships_path %></li>
         <%end%>
         <%if current_user  && IndividualRelationship.where(receiver_id: current_user.id ).first%>
               <li><%= link_to "Friend Requested!",individual_relationships_path %></li>
         <%end%>
        <div class="pull-right user-info">
           <% if current_user %>
              <%= image_tag(current_user.avatar.tiny.url) if current_user.avatar? %>
             Hello <%= current_user.email %>! <%= link_to "Sign out", destroy_user_session_path, method: :delete %>

           <% else %>
             <%= link_to "Sign In", new_user_session_path %> or
             <%= link_to "Sign Up", new_user_registration_path %>
           <% end %>
         </div>
      </ul>



      <%= yield %>
     </div>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

    <script src="/assets/components/friend_request_box.js"></script>
    <script src="/assets/components/notebook.js"></script>

</body>
</html>

Note that on the bottom of my layouts/application.html.erb there is a script tag that is <script src="/assets/components/friend_request_box.js"></script> This script tag is another react component that is actually visible on the page. 请注意,在我的layouts / application.html.erb的底部,有一个脚本标记,它是<script src="/assets/components/friend_request_box.js"></script>在页面上可见。 I have no clue why one is visible but the other is invisible. 我不知道为什么一个是可见的而另一个是不可见的。

I had a left over bootstrap class className="dropdown-menu" in one of the components. 在其中一个组件中,我剩下了一个引导类className="dropdown-menu" Once I removed that it started rendering. 一旦删除,它便开始渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM