简体   繁体   中英

Loading .JSON file with Ember Data

I want to load data from file komentari.json that is found within my folder and it changes when i insert something new, it is not always with just one comment in it. When I try to start my application it shows nothing.Here is my code.

app.js

App = Ember.Application.create();
App.Router.map(function() {
});

App.IndexRoute = Ember.Route.extend({
model: function() {
return this.get('store').find('comment');
}
});

App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: "http://localhost/proba/",
url: "komentari.json"
});

App.Comment = DS.Model.extend({
name: DS.attr('string'),
comment: DS.attr('string')

});

index page

<script type="text/x-handlebars" id="index">
<ul>
{{#each item in model}}
  <li>{{item.name}}</li>
 <li>{{item.comment}}</li>
{{/each}}
</ul>

komentari.json

{"comments":[{"name":"Name1",
             "comment":"Comment1"}]} 

You haven't defined any mapping. Try to apply what it's written here How to retrieve models from .json file in ember.js

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