2017-12-02 174 views
0

我打電話給我的分析服務器&使用Parse Javascript API將數據向下拖動到我的Angular V1應用程序(即JS或IO ?!)中。我的通話功能如下:獲取雙嵌套JSON響應解析Javascript API

$scope.getInventoryItems = function() { 

    var query = new Parse.Query("Inventory"); 
    query.include("product"); 
    query.include("retailer"); 
    query.find({ 

     success: function (results) { 

      $scope.inventoryItems = []; 

      for (i = 0; i < results.length; i++) { 

       var p = results[i].get("product"); 
       var r = results[i].get("retailer"); 

       var inventoryItem = { 

        objectId: results[i].id, 
        productObjectId: p.id, 
        barcode: p.get("barcode"), 
        productName: p.get("name"), 
        imageUrl: p.get("image"), 
        Qty: results[i].get("QTY"), 
        newQty: results[i].get("QTY"), 
        shoppingQty: 1, 
        retailerImage: r.get.Logo("url"), 
        retailerName: r.get("Name") 
       } 
       console.log(inventoryItem); 
       $scope.inventoryItems[$scope.inventoryItems.length] = inventoryItem; 

      } 

      $scope.$apply(); 

     }, 
     error: function (error) { 
      console.log("Query Error: " + error.message); 
     } 
    }) 
} 

繼承人的JSON服務器響應:

{ 
    "results": [{ 
     "objectId": "Fo02snRmlP", 
     "product": { 
      "objectId": "eCA7BwB7kF", 
      "barcode": 54775912, 
      "name": "Extra Peppermint Gum 5 Pack", 
      "image": "[image url removed]", 
      "createdAt": "2017-11-22T01:28:16.605Z", 
      "updatedAt": "2017-11-22T01:28:16.605Z", 
      "__type": "Object", 
      "className": "Products" 
     }, 
     "QTY": 4, 
     "createdAt": "2017-11-22T01:28:16.859Z", 
     "updatedAt": "2017-11-22T01:28:16.859Z", 
     "ACL": { 
      "NV6ubzeAHL": { 
       "read": true, 
       "write": true 
      } 
"retailer": { 
      "objectId": "u2qNoKDAWV", 
      "Name": "My Supermarket", 
      "createdAt": "2017-09-20T17:16:48.151Z", 
      "updatedAt": "2017-11-13T19:40:26.371Z", 
      "Logo": { 
       "__type": "File", 
       "name": "c600325c63f7fb252b36c08c8c6168ab_supermarket_logo_full.svg", 
       "url": "https://my-api.herokuapp.com//files/my-api/c600325c63f7fb252b36c08c8c6168ab_supermarket_logo_full.svg" 
      }, 
      "shortName": "supermarket", 
      "__type": "Object", 
      "className": "Retailers" 
     }, 
     } 
    }, { 

一切順利,除了我正努力用retailerImage: r.get.Logo("url")收集標誌URL。我將如何得到這個雙重嵌套物品?

感謝

+0

r.get:ACL.Logo( 'URL') –

回答

2

Logoretailer另一個屬性,對不對?看起來像你只需要使用r.get('Logo').url()

這裏的parse docs example

var profilePhoto = profile.get("photoFile"); 
$("profileImg")[0].src = profilePhoto.url(); 
+1

完蛋了。謝謝! –

+0

樂意協助! :d –