簡體   English   中英

Ember JS:嵌套的api路由

[英]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);

    }

  }

});

希望有幫助!

  1. 為了自定義任何端點,您必須為該模型編寫一個適配器。
  2. 適配器中有多個掛鈎。

    • host變量,在調用中得到前綴
    • pathForType(modelName) :可用於自定義給定類型的路徑
    • buildURL (modelName, id, snapshot, requestType, query) :提供更多定制

您可以參考這里的灰燼指南。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM