簡體   English   中英

RestAngular獲取JSON對象數組

[英]RestAngular get array of JSON objects

我正在嘗試使用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插件提供示例,我將非常高興。

謝謝你的幫助。

為了簡單起見,您可以使用Restangular 1.4並在響應上鏈接plain()函數

baseAccounts.getList().then(function(customers){
 $scope.myDate = customers.plain();

});

嘗試這個

var baseAccounts = Restangular.one('getAllCustomers');
  baseAccounts.getList().then(function(response) {
      $scope.myData = response.customers;
      console.log(response.customers);
    });

我也在尋找答案。 我沒有發現更好的東西,所以我采用了這種方法。

  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

暫無
暫無

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

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