Ember data EmbeddedRecordMixin

Ember data EmbeddedRecordMixin

本文关键字:EmbeddedRecordMixin data Ember      更新时间:2023-09-26

我一直在尝试加载一个嵌入式模型列表。我从演示中了解到 EmbeddedRecordsMixin 是要走的路,但这仍然失败了:"错误:断言失败:类型错误:工厂未定义" 我试图在我的灯具中将它们分开,这工作得很好,所以我一定在嵌入部分缺少一些东西,即使它遵循以下内容:http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html

那么这不适用于夹具吗?

var App = window.App = Ember.Application.create({
  LOG_TRANSITIONS: true
});
var attr = DS.attr;
App.Modificators = DS.Model.extend({
    "tpe": attr('string')
});
App.SpecialStuff = DS.Model.extend({
    "title": attr('string'),
    "body": attr('string'),
    "modificators": DS.hasMany('modificators')
});
App.SpecialStuffSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
    attrs: {
        "modificators": { embedded: 'always' }
    }
});
App.SpecialStuff.reopenClass({
    FIXTURES: [{
        "id": 79,
        "title": "fewfew",
        "body": "kkk",
        "modificators": [{
            "id": 1,
            "tpe": "vv",
        },
        {
            "id": 2,
            "tpe": "mv",
        }]
    }]
});
App.SpecialStuffIndexRoute = Ember.Route.extend({
  model: function (params) {
    return this.store.find('special_stuff');
  }
});
App.Router.map(function () {
  // Add your routes here
  this.resource('specialStuff', function() {});
});
Ember.Inflector.inflector.uncountable('modificators');
Ember.Inflector.inflector.uncountable('special_stuff');
App.ApplicationAdapter = DS.FixtureAdapter.extend({});

Ember Data 的 Fixture Adapter 不使用序列化程序来获取数据。 您最好使用 https://github.com/jakerella/jquery-mockjax 之类的东西来模拟 json 调用并使用 rest 适配器。

下面是一些示例:嵌入的 Ember 数据记录当前状态?

相关文章:
  • 没有找到相关文章