1

我正在使用 Ember Data 1.0.0-beta1 和 EmberJS 1.0.0。

当我的保存动作

App.UsersNewController = Ember.ObjectController.extend({
  actions: {
    save: function() {
      var self = this;
      self.content.save().then(function() {
        self.transitionToRoute('index');
      });
    },

    cancel: function() {
      this.content.deleteRecord();
      this.transitionToRoute('index');
    }
  }
});

被调用,它会抛出一个 Uncaught TypeError

Uncaught TypeError: Cannot call method 'lookup' of undefined ember-data.js?body=1:6576
DS.RESTAdapter.DS.Adapter.extend.serializerFor ember-data.js?body=1:6576
DS.RESTAdapter.DS.Adapter.extend.createRecord ember-data.js?body=1:6492
_commit ember-data.js?body=1:2490
(anonymous function) ember-data.js?body=1:1991
Ember.EnumerableUtils.forEach ember.js?body=1:1786
DS.Store.Ember.Object.extend.flushPendingSave ember-data.js?body=1:1978
DeferredActionQueues.flush ember.js?body=1:5463
Backburner.end ember.js?body=1:5547
Backburner.run ember.js?body=1:5586
Ember.run ember.js?body=1:5917
ActionHelper.registeredActions.(anonymous function).handler ember.js?body=1:32781
(anonymous function) ember.js?body=1:19003
Ember.handleErrors ember.js?body=1:557
(anonymous function) ember.js?body=1:18995
jQuery.event.dispatch jquery.js?body=1:5096
elemData.handle

编辑:这是路线

App.UsersNewRoute = Ember.Route.extend({
  model: function() {
    return this.store.createRecord('user');
  },

  setupController: function(controller, model) {
    controller.set('content', model);
  }
});

模型:

App.User = DS.Model.extend({
  email: DS.attr('string'),
  password: DS.attr('string'),
  passwordConfirmation: DS.attr('string')
});

店铺:

App.Store = DS.Store.extend
  revision: 13
  adapter: DS.RESTAdapter.create()
4

1 回答 1

1

似乎您的 RESTAdapter 没有对容器的引用。通常这将在 ember 创建适配器时设置 - 由于您手动创建实例,因此可能会丢失。尝试更改您的 App.Store 声明以仅使用默认值:

App.Store = DS.Store.extend({})
于 2013-09-03T02:08:13.930 回答