[英]Ember JS: Nested api routes
我需要對以下HTTP端點執行GET操作:
/api/v1/users/security_questions.json?memberID=1234
有人告訴我Ember JS不支持用戶/ security_questions之類的嵌套終結點,而我需要這樣做:
/api/v1/security_questions.json?memberID=1234
是否支持嵌套的API路由? 如果是這樣,如何在我的模型中實現它?
它不支持即用型,但是添加起來很容易。您需要在pathForType
中覆蓋pathForType
方法。
import Ember from 'ember';
export default DS.RESTAdapter.extend({
pathForType: function(type) {
// Assuming your model name is security_question
if (type === 'security_question' ) {
// If it's a security question, set this as the path
return 'users/security_questions.json';
} else {
// If not, call super to pluralize the model name as normal
return this._super(type);
}
}
});
希望有幫助!
適配器中有多個掛鈎。
host
變量,在調用中得到前綴 pathForType(modelName)
:可用於自定義給定類型的路徑 buildURL (modelName, id, snapshot, requestType, query)
:提供更多定制 您可以參考這里的灰燼指南。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.