简体   繁体   中英

EmberJS cannot call method 'lookup' of undefined when saving model

I'm using Ember Data 1.0.0-beta1 and EmberJS 1.0.0.

When my save action

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');
    }
  }
});

is called, it throws an 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

EDIT: Here's the route

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

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

Model:

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

Store:

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

Seems like your RESTAdapter does not have a reference to the container. Usually that would be set when ember creates the adapter - could be missing since you are creating an instance manually. Try changing your App.Store declaration to just use the default:

App.Store = DS.Store.extend({})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM