简体   繁体   中英

How to display JSON data from a rails API to ember.js view

I have a rails API that when I load a particular route it returns a JSON response to my browser. The URL I put in my browser is http://localhost:3000/api/csv_files

And the output looks like the following, API输出

Now I want to load this output / csv_files using ember.js but I am not entirely sure how this would work?

I included ember-rails gem in my rails app, and I have the appropriate files loaded in the rails app, but I am not sure how I could connect an ember template to the rails API controller to display the output.

You should use the route to load your data.

export default Ember.Route.extend({
 model() {
    return Ember.$.ajax({ url: 'http://localhost:3000/api/csv_files' })
 }
 });

And then in your template you can

{{#each model as |csv|}}
  {{csv.id}} - {{csv.csv_file_name}}
{{/each}}

You may want to define Models that represent you data, so that you can use a solution such as Ember Data.

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