首页 > 解决方案 > 从 oj.Collection 或 oj.Model 传递请求标头

问题描述

请通过告诉我如何在从 oj.Collection API 调用 REST 端点时传递标头(如授权等)来帮助我

https://learncodeshare.net/2017/03/29/making-a-rest-call-from-oracle-jet/

我从上面的链接中尝试了“customURL”,但无法获取标题

标签: oracle-jet

解决方案


collection.fetch()文档中没有明确提到它,但是您可以在调用该方法时将标头添加为对象输入属性之一。

例如:

self.model = oj.Model.extend({
        url: someURL,
        idAttribute: 'id'
});
var myModel = new self.model();
var collection = oj.Collection.extend({
        url: someURL,
        model: myModel
});
self.myCollection = new collection();

return new Promise(function (resolve, reject) {
    self.myCollection.fetch({
        headers: headers,
        success: function (collection, response, options) {
            resolve(response);
        }
    });
};

推荐阅读