获取双嵌套JSON响应解析Javascript API
我打电话给我的分析服务器&使用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。我将如何得到这个双重嵌套物品?
感谢
回答:
Logo
是retailer
另一个属性,对不对?看起来像你只需要使用r.get('Logo').url()
这里的parse docs example:
var profilePhoto = profile.get("photoFile"); $("profileImg")[0].src = profilePhoto.url();
以上是 获取双嵌套JSON响应解析Javascript API 的全部内容, 来源链接: utcz.com/qa/258328.html