特定型号的自定义REST网址 [英] Custom REST url for specific Model
本文介绍了特定型号的自定义REST网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与此模型一样:
App.Post = DS.Model.extend({
title:DS.attr('string'),
comments:DS.hasMany 'AppComment')
});
App.Comment = DS.Model.extend({
content:DS.attr('string'),
post:DS.belongsTo('App.Post')
});
此商店:
app.Store = DS.Store.extend({
revision:11,
adapter:DS.RESTAdapter.extend({
namespace:'rest'
})
});
我希望通过 / rest / post / {id } / comments
而不是 / rest / comments
这是默认行为。
是否可以配置休息 - 一个特定模型的网址?
解决方案
您可以向模型注册一个附加的适配器和范围。
App.Store.registerAdapter('App.Post',DS.RESTAdapter.extend({
url: / rest / post /
}));
Is there a way in Ember to configure a custom REST url for a specific Model?
Like with this model:
App.Post = DS.Model.extend({
title: DS.attr('string'),
comments: DS.hasMany('App.Comment')
});
App.Comment = DS.Model.extend({
content: DS.attr('string'),
post: DS.belongsTo('App.Post')
});
And this Store:
app.Store = DS.Store.extend({
revision : 11,
adapter : DS.RESTAdapter.extend({
namespace : 'rest'
})
});
I want that the comments are retrieved via /rest/post/{id}/comments
instead of /rest/comments
which is the default behaviour.
Is it possible to configure a rest-url for one specific Model?
解决方案
You can register an additional adapter and 'scope' it to your model.
App.Store.registerAdapter('App.Post', DS.RESTAdapter.extend({
url: "/rest/post/"
}));
这篇关于特定型号的自定义REST网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文