Emberjs + data + rails - 未捕获TypeError:无法调用未定义的方法“map”
当我正在尝试使用emberjs + ember数据从rails db加载数据时,我收到这个错误
When I am trying to load data from rails db with emberjs + ember data I am getting this error
未捕获TypeError:无法调用未定义的方法'map'
Uncaught TypeError: Cannot call method 'map' of undefined
这是咖啡版代码:
window.Cosmetics = Ember.Application.create
Cosmetics.store = DS.Store.create
revision: 4
adapter: DS.RESTAdapter.create
bulkCommit: false
Cosmetics.admin_user = DS.Model.extend({
name: DS.attr('string')
email: DS.attr('string')
});
Cosmetics.view = Ember.View.extend
templateName: 'ember/views/aaa'
Cosmetics.admin_user.reopenClass
url: 'admin/user'
Cosmetics.store.findAll(Cosmetics.admin_user)
控制器获取正确的JSON数据。我已经尝试映射从互联网上发现的例子中的代码,但没有任何帮助。有任何想法吗?我想我在做错了感谢您的任何帮助。
Controller gets proper JSON data. I've tried mapping the code from the examples found over the internet but nothing helped. Any ideas? I guess I'm doing sth wrong. Thanks in advance for any help.
发现问题,不确定解决方案。
Found the problem, not sure about the solution.
如果您的资源正在命名空间下,例如
If your resource is being served under a namespace, eg
App.Event = DS.Model.extend({
name: DS.attr('string'),
});
App.Event.reopenClass({
url: 'api/event'
})
当ember数据解析json响应时,它在 findAll c $ c> json [复数]
/ code>应该是 json ['events']
,但是复数被计算为 json ['api / events']
,因此出错。
When ember-data parses the json response, it does something like json[plural]
in findAll
which should be json['events']
, however the plural is calculated to be json['api/events']
, and hence the error. I'll ask around and probably raise a ticket for this.
更新
我已经为此此处创建了一张机票。
I've created a ticket for this here
解决方法
作为一个黑客,我这样做:
As a hack, I'm doing this:
def index
respond_to do |format|
format.json { render json: { 'api/events': Event.all } }
end
end