Javascript Sinatra api的Ember数据映射问题
我对ember非常陌生,目前正在开发一个由sinatra api支持的(非常)轻量级的ember应用程序。我在将api提供的JSON映射到实际的ember对象时遇到了一些问题。每当我尝试使用此数据呈现模板时,都会收到“未捕获错误:断言失败:您的服务器返回了一个密钥为0的哈希,但您没有映射” 这是我的API的JSON格式:Javascript Sinatra api的Ember数据映射问题,javascript,ember.js,sinatra,Javascript,Ember.js,Sinatra,我对ember非常陌生,目前正在开发一个由sinatra api支持的(非常)轻量级的ember应用程序。我在将api提供的JSON映射到实际的ember对象时遇到了一些问题。每当我尝试使用此数据呈现模板时,都会收到“未捕获错误:断言失败:您的服务器返回了一个密钥为0的哈希,但您没有映射” 这是我的API的JSON格式: [{"sha":"c1133d9ec33"},{"sha":"2b2d4dd4590"}.....] 我的余烬代码片段如下: App.Store = DS.Store.ext
[{"sha":"c1133d9ec33"},{"sha":"2b2d4dd4590"}.....]
我的余烬代码片段如下:
App.Store = DS.Store.extend({
LOG_TRANSITIONS: true,
revision: 12,
});
App.Router.map(function(){
this.resource('commits', function(){
this.route('commits', {path: '/:sha'});
});
});
//COMMITS
App.CommitsRoute = Ember.Route.extend({
model: function(){
return App.Commit.find(); //pulls all commts at /commits
}
});
//COMMIT
App.CommitRoute = Ember.Route.extend({
model: function(params){
return App.Commit.find(params.sha);
}
});
App.Commit = DS.Model.extend({
sha: DS.attr('string'),
image_url: function() {
return 'http://localhost:9393/commits' + this.get('sha');
}.property('sha')
});
了解发生这种情况的原因吗?余烬数据希望您的API返回命名根 您需要更新API以返回带有根的JSON
{“提交”:[{“sha”:“c1133d9ec33”},{“sha”:“2b2d4dd4590”}……]}