簡體   English   中英

為什么我的自定義ember-data適配器出現此錯誤:無法調用未定義的方法'lookupFactory'

[英]Why am I getting this error with my custom ember-data adapter: Cannot call method 'lookupFactory' of undefined

我剛剛開始使用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');
  }
});

那個文檔有點不穩定,如果你想設置一個不同的商店等,但如果你想使用內置商店,你會這樣做。

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({

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM