【发布时间】:2026-02-06 02:45:01
【问题描述】:
我的 RESTAdapter 配置:
App.ApplicationAdapter = DS.RESTAdapter.extend
namespace: '/api'
我的模特:
module.exports = App.Cat = DS.Model.extend
name: DS.attr 'string'
description: DS.attr 'string'
picture: DS.attr 'string'
location: DS.attr 'string'
profileStyle: DS.attr 'string'
created: DS.attr 'date'
我的路线:
Cat = require '../../models/cat'
App.CatNewRoute = Em.Route.extend
model: ->
@store.createRecord(Cat, {
created: new Date()
})
我的控制器:
App.CatNewController = Em.ObjectController.extend
actions:
addCat: ->
console.log 'saving...'
@get('model').save().then ->
console.log 'all done'
我已经通过 Ember 检查器验证了我的模型具有在保存时通过模板上的表单分配的所有属性(除了为 null 的 id - 我认为这是正常的,默认情况下是 Ember使用服务器分配给模型的 ID)。每当我保存模型时,我都会收到错误:
Uncaught TypeError: Cannot read property 'typeKey' of undefined
在ember数据源代码这里出现这个错误:
if (container) {
adapter = container.lookup('adapter:' + type.typeKey) || container.lookup('adapter:application');
}
我正在使用 Ember-data 1.0.0 beta 3-2 和 Ember 1.0.0-4。我已经尝试了几个不同版本的 Ember 数据以达到相同的效果。
jsBin 中的近似:http://jsbin.com/ixIqIjI/6/edit?html,js,console,output
这个 jsBin 也出现 typeKey 错误。
【问题讨论】:
-
你有没有想过这个问题?
标签: ember.js