使用Ember数据加载.JSON文件

时间:2014-06-13 11:06:57

标签: javascript json ember.js ember-data

我想从我的文件夹中找到的文件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"}]} 

1 个答案:

答案 0 :(得分:0)

您还没有定义任何映射。 尝试应用它在这里写的内容 How to retrieve models from .json file in ember.js