Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 指定可以在其中找到模型数据的URL_Ember.js_Ember Data - Fatal编程技术网

Ember.js 指定可以在其中找到模型数据的URL

Ember.js 指定可以在其中找到模型数据的URL,ember.js,ember-data,Ember.js,Ember Data,我有这些模型: App.Profile = DS.Model.extend({ name : DS.attr('string'), type : DS.attr('string') }); App.User = App.Profile.extend({ email : DS.attr('string') }); App.Company = App.Profile.extend({ vat : DS.attr('string') }); App.Profi

我有这些模型:

App.Profile = DS.Model.extend({
    name  : DS.attr('string'),
    type  : DS.attr('string')
});

App.User = App.Profile.extend({
    email : DS.attr('string')
});

App.Company = App.Profile.extend({
    vat : DS.attr('string')
});

App.Profile.FIXTURES = [
    { id: 'me',         type: 'user'   , name: 'Max Smith',        email: 'max.smith@email.com'},
    { id: 'my-company', type: 'company', name: 'Good Company Inc', vat: 'B456DF' },
];
用户
公司
的数据可在
配置文件
夹具
中找到。如何配置
用户
公司
型号以使用该通用
夹具
?这样做不行:

因为我想真正拥有一个单一的公共端点,而不是伪造它来复制装置

我真正的目标是能够访问同一URL中的
用户
公司
对象的后端:
/api/profile
;如果有人能澄清这一点,那么
夹具
问题是次要的(我只是对它感兴趣,以便让它发挥作用)

编辑 对于
余烬数据
,可以配置和。但我要配置的是在全局api名称空间中找到每个模型的位置。也就是说,我不希望
ember data
根据模型名称推断API端点,但我希望显式地配置它


这可能吗?

我认为目前ember data没有这个选项,所以我的建议是使用它,因为它更灵活,并且您可以为每个类配置一个适配器

App.Profile = Ember.Model.extend({
    name  : Ember.attr(),
    type  : Ember.attr()
});

App.User = Ember.Profile.extend({
    email : Ember.attr()
});

// when using fixtures
App.User.adapter = Ember.FixtureAdapter.create();

// or when using rest adapter
App.User.url = '/api/profile';
App.User.adapter = Ember.RESTAdapter.create();

App.Company = Ember.Profile.extend({
    vat : Ember.attr()
});

// when using fixtures
App.Company.adapter = Ember.FixtureAdapter.create();

// or when using rest adapter
App.Company.url = '/api/profile';
App.Company.adapter = Ember.RESTAdapter.create();

// When using fixtures
// I think that this cannot be avoided
App.User.FIXTURES = App.Company  = [
    { id: 'me',         type: 'user'   , name: 'Max Smith',        email: 'max.smith@email.com'},
    { id: 'my-company', type: 'company', name: 'Good Company Inc', vat: 'B456DF' },
];
App.Profile = Ember.Model.extend({
    name  : Ember.attr(),
    type  : Ember.attr()
});

App.User = Ember.Profile.extend({
    email : Ember.attr()
});

// when using fixtures
App.User.adapter = Ember.FixtureAdapter.create();

// or when using rest adapter
App.User.url = '/api/profile';
App.User.adapter = Ember.RESTAdapter.create();

App.Company = Ember.Profile.extend({
    vat : Ember.attr()
});

// when using fixtures
App.Company.adapter = Ember.FixtureAdapter.create();

// or when using rest adapter
App.Company.url = '/api/profile';
App.Company.adapter = Ember.RESTAdapter.create();

// When using fixtures
// I think that this cannot be avoided
App.User.FIXTURES = App.Company  = [
    { id: 'me',         type: 'user'   , name: 'Max Smith',        email: 'max.smith@email.com'},
    { id: 'my-company', type: 'company', name: 'Good Company Inc', vat: 'B456DF' },
];