首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Ember data中的字符串名称解析模型类?

如何从Ember data中的字符串名称解析模型类?
EN

Stack Overflow用户
提问于 2013-04-11 23:36:33
回答 1查看 853关注 0票数 2

我正在尝试使用ember-data,并且我需要能够动态解析给定字符串的模型名称。

我查看了ember-data代码库,但在那里找不到任何东西。然后我在ember中发现了这个:

代码语言:javascript
复制
/**
  @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) {

我会假设ember-data连接到这个功能中,所以我可以这样做:

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

但是,唉,不是的.

也许这就是我们要走的路?(来自store.js第~1500行)

代码语言:javascript
复制
  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?

EN

回答 1

Stack Overflow用户

发布于 2013-04-21 01:33:51

如果你声明了你的模型,序列化程序就知道该怎么做。请参阅DS.Serializer typeFromAlias

https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/serializer.js#L1103

你的弦是从哪里来的?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15953026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档