2013-04-11 17 views
2

我試圖使用ember-data,我需要能夠動態地解析給定一個字符串的模型名稱。如何從Ember數據中的字符串名稱解析模型類?

我查看了ember-data代碼庫,但在那裏找不到任何東西。然後我發現這燼:

/** 
    @private 

    This function defines the default lookup rules for container lookups: 

    * templates are looked up on `Ember.TEMPLATES` 
    * other names are looked up on the application after classifying the name. 
    For example, `controller:post` looks up `App.PostController` by default. 
    * if the default lookup fails, look for registered classes on the container 

    This allows the application to register default injections in the container 
    that could be overridden by the normal naming convention. 

    @param {Ember.Namespace} namespace the namespace to look for classes 
    @return {any} the resolved value for a given lookup 
*/ 
function resolverFor(namespace) { 

    resolve: function(fullName) { 
    return this.resolver(fullName) || this.registry.get(fullName); 
    }, 

    normalize: function(fullName) { 
    return fullName; 
    }, 

    lookup: function(fullName, options) { 

我都會以爲,鉤入此功能燼數據,所以我可以做某事像這樣:

App.resolver.resolveModel "model:#{modelName}"

但是,唉,不...

也許這是要走的路? (from store.js line〜1500)

typeMapFor: function(type) { 
    var typeMaps = get(this, 'typeMaps'); 
    var guidForType = Ember.guidFor(type); 

    var typeMap = typeMaps[guidForType]; 

    if (typeMap) { 
     return typeMap; 
    } else { 
     return (typeMaps[guidForType] = 
     { 
      idToCid: {}, 
      clientIds: [], 
      recordArrays: [] 
     }); 
    } 
    }, 

看起來商店內部有一些typeMaps?

回答

相關問題