【发布时间】:2018-03-23 06:00:50
【问题描述】:
我使用的是 ember 2.18,在此更新请求是 PATCH。但是,后端在 SAILS 中,不支持 PATCH。因此,我必须将补丁请求转换为 PUT。
我看到this 问题,人们似乎已经在那里解决了它。但这对我不起作用。代码如下:
import App from './../app';
import DS from "ember-data";
import { computed } from "@ember/object";
import { camelize } from '@ember/string';
import JSONAPIAdapter from "ember-data/adapters/json-api";
export default DS.JSONAPIAdapter.extend({
coalesceFindRequests: true,
host: App.GPT.Configuration.restServer,
methodForRequest: ({ requestType }) => {
console.log('Log')
if (requestType === "updateRecord") {
return "PUT";
}
return this._super(...arguments);
},
pathForType(type) {
return camelize(type) + 's';
},
headers: computed(function () {
if (!App.StoreUtil.getSessionId()) {
if (App.GPT.ApplicationController) {
App.GPT.ApplicationController.set("hasMessages", [
{
message: "Session expired."
}
]);
App.GPT.ApplicationController.transitionToRoute("/");
} else {
window.location = "/";
}
}
return {
sid: App.StoreUtil.getSessionId()
};
}).volatile()
});
添加的将请求转换为 PUT 的代码是:
methodForRequest: ({ requestType }) => {
console.log('Log')
if (requestType === "updateRecord") {
return "PUT";
}
return this._super(...arguments);
}
但是,该方法根本没有被调用。有趣的是每个请求都会调用 pathForType。
【问题讨论】:
标签: javascript ember.js ember-data httprequest