下面是我的 AirTableService.js
(function () {
"use strict";
var AirTableService = function ($http, $q) {
var AirTableMethods = {
getMyRounds: function(AirTable_secret){
var deferObject_myRounds;
var myRounds_promise = $http.get('https://api.airtable.com/v0/XXXXXXX/Rounds?view=Main%20View&maxRecords=10&callback=JSON_CALLBACK', {
headers : {
'Authorization' : AirTable_secret.apikey,
'Content-Type' : 'application/json'
}
});
deferObject_myRounds = deferObject_myRounds || $q.defer();
myRounds_promise.then(function(data){
deferObject_myRounds.resolve(data);
});
return deferObject_myRounds.promise;
}
};
return AirTableMethods;
};
AirTableService.$inject = ['$http', '$q'];
angular.module('appGolf')
.service('AirTableService', AirTableService);
}());
在那里,你可以看到,使用AirTable的api
我想GET
从我的表中的数据。我正在传递参数view
,maxRecords
并且可以正常工作。我可以通过的文件说明sort
,
然后我改为
https://api.airtable.com/v0/XXXXXXX/Rounds?view=Main%20View&maxRecords=10&sort=[{field:'RoundID',direction:'desc'}]&callback=JSON_CALLBACK
显然这是行不通的,它给了我这个错误,我知道这是因为是a并且我知道我是如何通过的,这是不正确的。sort
array of objects
我的问题是,您如何做到这一点AngularJS
?
先感谢您。
在这里找到答案正如那里提到的,我需要添加,
paramSerializer: '$httpParamSerializerJQLike',
如果您有兴趣,我的功能现在看起来像
var myRounds_promise = $http.get('https://api.airtable.com/v0/XXXXX/Rounds?callback=JSON_CALLBACK', {
params: {
view: 'Main View',
maxRecords: 10,
sort: [{"field": 'RoundID', "direction":'desc'}]
},
paramSerializer: '$httpParamSerializerJQLike',
headers : {
'Authorization' : AirTable_secret.apikey,
'Content-Type' : 'application/json'
}
});
感谢大家的建议和帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句