用烬数据加载.json文件

Loading .JSON file with Ember Data

本文关键字:json 文件 加载 数据      更新时间:2023-09-26

我想从文件komentari加载数据。Json是在我的文件夹中找到的,当我插入新的东西时它会改变,它并不总是只有一个注释在里面。当我试图启动我的应用程序时,它什么也没有显示。这是我的代码。

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')
});

索引页

<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"}]} 

您没有定义任何映射。试着应用这里写的东西如何从ember.js中的.json文件中检索模型