Emberjs嵌入式模型但Adapter.map不存在

时间:2013-10-17 09:31:53

标签: ember.js ember-data

emberjs guide说明了以下关于嵌套模型的内容:

  

当您拥有嵌入数据不使用的数据结构时   需要id,你必须指定belongsTo关系   由hasMany关系包含。

     

为此,您需要扩展应用正在使用的适配器   使用嵌入式结构加载数据。

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

App.Post = DS.Model.extend({
  comments: DS.hasMany('comment')
});


App.Adapter.map('post', {
  comments: { embedded: 'always' }
});

我正在使用restAdapter所以我认为这样做是正确的:

App.Adapter.map('checkData', {  //'App.CheckData' isn't working either
  items: { embedded: 'always' }
});

但后来我收到以下错误:(tldr; DS.RESTAdapter没有方法'map')

Uncaught TypeError: Object function () {
    if (!wasApplied) {
      Class.proto(); // prepare prototype...
    }
    o_defineProperty(this, GUID_KEY, undefinedDescriptor);
    o_defineProperty(this, '_super', undefinedDescriptor);
    var m = meta(this), proto = m.proto;
    m.proto = this;
    if (initMixins) {
      // capture locally so we can clear the closed over variable
      var mixins = initMixins;
      initMixins = null;
      this.reopen.apply(this, mixins);
    }
    if (initProperties) {
      // capture locally so we can clear the closed over variable
      var props = initProperties;
      initProperties = null;

      var concatenatedProperties = this.concatenatedProperties;

      for (var i = 0, l = props.length; i < l; i++) {
        var properties = props[i];

        Ember.assert("Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Ember.Mixin));

        for (var keyName in properties) {
          if (!properties.hasOwnProperty(keyName)) { continue; }

          var value = properties[keyName],
              IS_BINDING = Ember.IS_BINDING;

          if (IS_BINDING.test(keyName)) {
            var bindings = m.bindings;
            if (!bindings) {
              bindings = m.bindings = {};
            } else if (!m.hasOwnProperty('bindings')) {
              bindings = m.bindings = o_create(m.bindings);
            }
            bindings[keyName] = value;
          }

          var desc = m.descs[keyName];

          Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty));
          Ember.assert("Ember.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('._super') !== -1));
          Ember.assert("`actions` must be provided at extend time, not at create time, when Ember.ActionHandler is used (i.e. views, controllers & routes).", !((keyName === 'actions') && Ember.ActionHandler.detect(this)));

          if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) {
            var baseValue = this[keyName];

            if (baseValue) {
              if ('function' === typeof baseValue.concat) {
                value = baseValue.concat(value);
              } else {
                value = Ember.makeArray(baseValue).concat(value);
              }
            } else {
              value = Ember.makeArray(value);
            }
          }

          if (desc) {
            desc.set(this, keyName, value);
          } else {
            if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) {
              this.setUnknownProperty(keyName, value);
            } else if (MANDATORY_SETTER) {
              Ember.defineProperty(this, keyName, null, value); // setup mandatory setter
            } else {
              this[keyName] = value;
            }
          }
        }
      }
    }
    finishPartial(this, m);
    this.init.apply(this, arguments);
    m.proto = proto;
    finishChains(this);
    sendEvent(this, "init");
  } has no method 'map' app.js:96
(anonymous function)

所以我检查了在RestAdapter上调用map函数是否正确。但是在different page我发现了这个:

App.Person = DS.Model.extend({
  lastName: DS.attr('string')
});
DS.RESTAdapter.map('App.Person', {
  lastName: { key: 'lastNameOfPerson' }
});

文档错了吗?

PS:

DEBUG: Ember.VERSION : 1.0.0 ember-1.0.0.js:394
DEBUG: Handlebars.VERSION : 1.0.0 ember-1.0.0.js:394
DEBUG: jQuery.VERSION : 1.9.1 

0 个答案:

没有答案