【问题标题】:Why am I getting this error with my custom ember-data adapter: Cannot call method 'lookupFactory' of undefined为什么我的自定义 ember-data 适配器出现此错误:无法调用未定义的方法“lookupFactory”
【发布时间】:2013-12-03 02:31:11
【问题描述】:

我刚开始使用 Ember,并使用 http://emberjs.com/api/data/classes/DS.Adapter.html 的文档创建自定义适配器以访问 SOAP Web 服务。但是,当我尝试访问使用此适配器的商店时,我收到此错误:

TypeError: Cannot call method 'lookupFactory' of undefined

这是我的代码:

App = Ember.Application.create();

App.RMSoapAdapter = DS.Adapter.extend({

    find: function(store, type, id) {
        switch(type) {
        case 'group-mailbox':
            return getGroupMailboxForStore(id, store);
            break;
        default:
            throw 'Unknown object type: ' + String(type);
            break;
        }
    }
});

App.store = DS.Store.create({
  adapter: App.RMSoapAdapter.create(),
});


App.IndexRoute = Ember.Route.extend({
  model: function() {
    var store = App.store;
      return store.find('group-mailbox');
  }
});

【问题讨论】:

    标签: ember.js ember-data


    【解决方案1】:

    那个文档有点不靠谱,如果你想建立一个不同的商店等,但如果你想使用内置商店,你会这样做。

    App.ApplicationAdapter = App.RMSoapAdapter;
    
    App.IndexRoute = Ember.Route.extend({
      model: function() {
          return this.store.find('group-mailbox');
      }
    });
    

    并且类型必须是有效的 DS 模型,它正在查找 group-mailbox 并且它将在 App.GroupMailbox 中发送,而不是字符串。

    App.GroupMailbox = DS.Model.extend({
    
    });
    

    【讨论】:

    • 做到了。谢谢!也感谢您注意到我的另一个错误。
    猜你喜欢
    • 1970-01-01
    • 2013-04-26
    相关资源
    最近更新 更多