简体   繁体   中英

React.js on Rails Order Array

how i can show my array in order ASC or DESC an example.

here is my react component

var News = React.createClass({

 displayName: 'News',

  render: function() {
    return (
           <div>
             <div>
             <h4>{this.props.news.title}</h4></div>
             <div>{this.props.news.created_at}</div>
             <div>{this.props.news.body}</div>


           </div>
    );
   }
 }); 

and here is my render

<% @news.each do |news|  %>
                <%= react_component('News', { :news => news }) %>
<% end %>

Order the news in your controller @news = News.all.order(created_at: :asc)

:asc can be swapped out for :desc .

Try to not modify the data from react, but only present it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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