我正在尝试使用restangular从服务器获取JSON响应。
var baseAccounts = Restangular.one('getAllCustomers');
baseAccounts.getList().then(function(customers) {
$scope.myData = customers;
console.log(customers);
});
问题在于我总是以下列格式得到答案:
0: Object
1: Object
2: Object
addRestangularMethod: function bound() {
all: function bound() {
allUrl: function bound() {
clone: function bound() {
customDELETE: function bound() {
customGET: function bound() {
customGETLIST: function bound() {
但我想只返回纯粹的JSON结构。如果有人在这里放置RestAngular插件的例子,我会很高兴。
感谢您的帮助。
答案 0 :(得分:5)
为简单起见,您可以使用Restangular 1.4并在响应
上链接plain()函数baseAccounts.getList().then(function(customers){
$scope.myDate = customers.plain();
});
答案 1 :(得分:0)
试试这个
var baseAccounts = Restangular.one('getAllCustomers');
baseAccounts.getList().then(function(response) {
$scope.myData = response.customers;
console.log(response.customers);
});
答案 2 :(得分:0)
我也在寻找答案。我没有找到更好的东西,所以我实现了这一点。
var baseAccounts = Restangular.one('getAllCustomers');
baseAccounts.getList().then(function(customers) {
var tmp = [];
customers.forEach(function(element){
tmp.push(element);
});
$scope.myData = tmp;
console.log(customers);
});
然后返回
0: Object
1: Object
2: Object