How to export nested json array to pdf using PDFMAKE Angular - javascript

I have used Angular as programming language for my project and i am a beginner. But i am stuck at the point where i have to generate PDF of my JSON response.
Looked at the documentation of PDFMAKE to achieve the same, but couldnot figure out how to implement it and come out with the output as shown in following image.
Output Structure Image
The JSON response is as follows:
{
"statusCode": true,
"data": [
{
"partyId": 1,
"partyIdDisp": "1/PA/2077",
"createdDate": "2077/05/03",
"partyName": "Roshan Basnet",
"contactNumber": 9841040791,
"companyName": "Butwal Poultry",
"panNumber": 321654,
"address": "Butwal, Nepal",
"saleDetails": [
{
"_id": "5f5b234cbac67e377c2a700f",
"saleId": 1,
"saleIdDisp": "1/S/2077",
"createdDate": "2077/05/26",
"saleType": "Credit",
"customerId": 1,
"customerName": "Roshan Basnet",
"contactNumber": 9841040791,
"billingName": "Butwal Poultry",
"billingAddress": "Butwal, Nepal",
"billDate": "2077/05/26",
"itemDetails": [
{
"_id": "5f5b234cbac67e377c2a7010",
"itemId": 1,
"itemName": "Chicken",
"quantity": 10,
"unit": "KG",
"piece": 5,
"receiptNo": null,
"billNo": 366,
"unitPrice": 310,
"itemAmount": 3100
}
],
"totalQuantity": 10,
"paymentMethod": "Cash",
"subTotal": 3100,
"amountInWords": "three thousand one hundred only",
"outstandingBalance": 0,
"receivedAmount": 3000,
"balanceAmount": 100,
"__v": 0
},
{
"_id": "5f5b2375bac67e377c2a7012",
"saleId": 2,
"saleIdDisp": "2/S/2077",
"createdDate": "2077/05/26",
"saleType": "Credit",
"customerId": 1,
"customerName": "Roshan Basnet",
"contactNumber": 9841040791,
"billingName": "Butwal Poultry",
"billingAddress": "Butwal, Nepal",
"billDate": "2077/05/26",
"itemDetails": [
{
"_id": "5f5b2375bac67e377c2a7013",
"itemId": 2,
"itemName": "Mutton",
"quantity": 5,
"unit": "KG",
"piece": 0,
"receiptNo": null,
"billNo": 266,
"unitPrice": 1200,
"itemAmount": 6000
},
{
"_id": "5f5b2375bac67e377c2a7014",
"itemId": 3,
"itemName": "Eggs",
"quantity": 10,
"unit": "Crate",
"piece": 0,
"receiptNo": null,
"billNo": 366,
"unitPrice": 390,
"itemAmount": 3900
}
],
"totalQuantity": 15,
"paymentMethod": "Cash",
"subTotal": 10000,
"amountInWords": "ten thousand only",
"outstandingBalance": 100,
"receivedAmount": 5000,
"balanceAmount": 5000,
"__v": 0
}
]
}
]
}
A code snippet how to generate a pdf output as per the structure in the image would be helpful.

Related

How to filter product data when checkbox selected is true in reactjs?

I have searched a lot regarding filter of product data using checkbox but couldn't able to find the right answer for my issue.
Problem: I'm making a product filter page using checkbox in react but could not found the proper way to filter the true value of object key.
ie. I have to only filter object key value === true. Below array object is after checkbox selection before the selection it will be falsy value.
const category = [
{
"type":"Color",
"options":[
{
"key":"Red",
"value":true
},
{
"key":"Blue",
"value":false
},
{
"key":"Green",
"value":true
}
]
},
{
"type":"Gender",
"options":[
{
"key":"Men",
"value":true
},
{
"key":"Women",
"value":false
}
]
},
{
"type":"Price",
"options":[
{
"key":"0 - Rs. 250",
"from":0,
"to":250,
"value":false
},
{
"key":"Rs. 251 - 450",
"from":251,
"to":450,
"value":true
},
{
"key":"Rs. 451 & above",
"from":451,
"to":"Number.MAX_VALUE",
"value":false
}
]
},
{
"type":"Type",
"options":[
{
"key":"Polo",
"value":false
},
{
"key":"Hoodie",
"value":false
},
{
"key":"Basic",
"value":true
}
]
}
]
const productData = [
{
"id": 1,
"name": "Black Polo",
"type": "Polo",
"price": 250,
"currency": "INR",
"color": "Black",
"gender": "Men",
"quantity": 3
},
{
"id": 2,
"name": "Blue Polo",
"type": "Polo",
"price": 350,
"currency": "INR",
"color": "Blue",
"gender": "Women",
"quantity": 3
},
{
"id": 3,
"name": "Pink Polo",
"type": "Polo",
"price": 350,
"currency": "INR",
"color": "Pink",
"gender": "Women",
"quantity": 6
},
{
"id": 4,
"name": "Black Hoodie",
"type": "Hoodie",
"price": 500,
"currency": "INR",
"color": "Black",
"gender": "Men",
"quantity": 2
},
{
"id": 5,
"name": "Green Polo",
"type": "Polo",
"price": 250,
"currency": "INR",
"color": "Green",
"gender": "Men",
"quantity": 1
},
{
"id": 6,
"name": "Green Polo",
"type": "Polo",
"price": 350,
"currency": "INR",
"color": "Green",
"gender": "Women",
"quantity": 1
},
{
"id": 7,
"name": "Blue Hoodie",
"type": "Hoodie",
"price": 500,
"currency": "INR",
"color": "Blue",
"gender": "Women",
"quantity": 2
},
{
"id": 8,
"name": "Black Hoodie",
"type": "Hoodie",
"price": 500,
"currency": "INR",
"color": "Black",
"gender": "Women",
"quantity": 5
}]
Now,I need filtered product data from the above category data and product-data.
Here's my Codesandbox link for this.

Update object from values in other array

I have two arrays, BasicItem1 & BasicItem2, I want to update the rate in details array of BasicItem1 with the rate of items in details array of BasicItem2.
For Example change rate of "Almond Flour" in BasicItem 1 from "1350" to "1250" and for "Egg White 1" from "15" to "225"
BasicItems1:
[{
"_id": "5f4249d613ed7a94355aac67",
"name": "New Macaron sshell",
"details": [
{
"_id": "5f397abb59ad0ba71f27fa93",
"name": "Egg white 1",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 15,
"quantityInRecipe": 121
},
{
"_id": "5f397adb59ad0ba71f27fa94",
"name": "Egg white 2",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 18,
"quantityInRecipe": 121,
},
{
"_id": "5f36cdfc875da6156c9a078f",
"name": "Almound Flour",
"baseQuantity": 1000,
"baseUnit": "gm",
"rate": "1350",
"quantityInRecipe": "350",
}
]
}]
BasicItem2
[{
"_id": "5f4249d613ed7a94355aac67",
"name": "New Macaron sshell",
"details": [
{
"_id": "5f397abb59ad0ba71f27fa93",
"name": "Egg white 1",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 225,
"quantityInRecipe": 121
},
{
"_id": "5f397adb59ad0ba71f27fa94",
"name": "Egg white 2",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 18,
"quantityInRecipe": 121,
},
{
"_id": "5f36cdfc875da6156c9a078f",
"name": "Almound Flour",
"baseQuantity": 1000,
"baseUnit": "gm",
"rate": "1250",
"quantityInRecipe": "350",
}
]
}]
This will do it
let basicItem1Details = basicItem1[0].details
let basicItem2Details = basicItem2[0].details
basicItem1Details.forEach((detail, index) => {
if (detail._id === basicItem2Details[index]._id)
detail.rate = basicItem2Details[index].rate
})

Update the value in nested object [duplicate]

This question already has answers here:
How to find object in array by property in javascript?
(3 answers)
Closed 2 years ago.
I have the Basic Recipe array with the details objects:
I want to be able to update the value of specific item inside the details i.e item with ID 5f3aadd5d756e9341ef74e2b
{
"brandName": "Piatto",
"_id": "5f3aadd5d756e9341ef74e29",
"name": "Test",
"rate": 89,
"baseQuantity": 1000,
"baseUnit": "gm",
"details": [
{
"_id": "5f3aadd5d756e9341ef74e2b",
"rawMaterial": "Egg white 1",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 12,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "ml",
"displayRateUnit": "1/2 lit."
},
{
"_id": "5f3aadd5d756e9341ef74e2a",
"rawMaterial": "Egg white 2",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 14,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "gm",
"displayRateUnit": "1/2 lit."
}
],
"__v": 0
}
Please help!
Try this.
var data = {
"brandName": "Piatto",
"_id": "5f3aadd5d756e9341ef74e29",
"name": "Test",
"rate": 89,
"baseQuantity": 1000,
"baseUnit": "gm",
"details": [{
"_id": "5f3aadd5d756e9341ef74e2b",
"rawMaterial": "Egg white 1",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 12,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "ml",
"displayRateUnit": "1/2 lit."
},
{
"_id": "5f3aadd5d756e9341ef74e2a",
"rawMaterial": "Egg white 2",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 14,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "gm",
"displayRateUnit": "1/2 lit."
}
],
"__v": 0
};
var idToBeUpdate = '5f3aadd5d756e9341ef74e2b'
data.details.forEach(x => {
if (x._id === idToBeUpdate) {
x.rawMaterial = "Egg white 3 <updated>"
}
});
console.log(data);
Ciao, you could use a filter function to get element you want to update based on _id, and then modify it like:
let input = {
"brandName": "Piatto",
"_id": "5f3aadd5d756e9341ef74e29",
"name": "Test",
"rate": 89,
"baseQuantity": 1000,
"baseUnit": "gm",
"details": [
{
"_id": "5f3aadd5d756e9341ef74e2b",
"rawMaterial": "Egg white 1",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 12,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "ml",
"displayRateUnit": "1/2 lit."
},
{
"_id": "5f3aadd5d756e9341ef74e2a",
"rawMaterial": "Egg white 2",
"brandName": "Bisleri",
"supplier": "Dasnya",
"type": "Solid",
"baseQuantity": 100,
"baseUnit": "gm",
"rate": 14,
"quantityInRecipe": 0,
"costOfRawMaterial": 0,
"recipeUnit": "gm",
"displayRateUnit": "1/2 lit."
}
],
"__v": 0
}
let elementToUpdate = input.details.filter(el => el._id === "5f3aadd5d756e9341ef74e2b")[0]
// this is the element filtered by _id
console.log(elementToUpdate)
//lets say you want to update rawMaterial
elementToUpdate.rawMaterial += ", Egg black 2"
console.log(elementToUpdate)
// this is the input object modified
console.log(input)

How to identify extracted obj file from response of autodesk model derivative API?

In Model Derivative API (OBJ Extraction using DbIds), I retrieved OBJ URN using API. As Response shows below, it returns all children's URN for obj, mtl, and its zip. How do we identify the recent extraction as every child does have its own guid?
I have attached whole response JSON. What I am looking for is the second obj file which has extracted using several dbids like "17,19,21,22,23...". The first child obj was created long ago. How do I differentiate the new obj. As GUID's are different for every node. How do I identify which GUID.obj belongs to my desired extraction.
** Edited **
I am looking for identifying extracted wavefronts object files( not objectids and name which gets from metadata). Suppose if I extracted 2 object files from one model, then after completion of object file geometry extraction job, 6 file gets generated and store in bucket.
first .obj (guid = /output/geometry/e72fa6b3-4fc2-3c86-8424-5d0755539c0d.obj)
first .mtl
first .zip
second .obj
second .mtl
second .zip
Every file does have different GUID.Type as name. and those guid's are random and never shown while calling of extraction API or while getting its progress.
these are shown in below JSON file. Now suppose I extracted 10 different object files from one model. that means in bucket 30 new file URN will be generated.
And it is getting very hard to identify.
The Solution could have been if I extract obj geometry from model, I should get that particular obj, mtl, zips guid. IF I am getting only 3 ids then I can map those and download it from bucket.
What is happening now is I am getting all obj's guid (suppose 30 ) after calling get manifest GET :urn/manifest . And I am not understanding what obj file belong to which extraction.
{
"type": "manifest",
"hasThumbnail": "true",
"status": "success",
"progress": "complete",
"region": "US",
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA",
"version": "1.0",
"derivatives": [{
"name": "rme_advanced_sample_project.nwd",
"hasThumbnail": "true",
"status": "success",
"progress": "complete",
"outputType": "svf",
"children": [{
"guid": "763d96f1-0812-451d-b3a1-a51a27eba53b",
"name": "rme_advanced_sample_project.rvt",
"hasThumbnail": "true",
"role": "3d",
"viewableID": "rme_advanced_sample_project.rvt",
"progress": "complete",
"useAsDefault": true,
"status": "success",
"type": "geometry",
"children": [{
"guid": "1e172e73-2305-4eb8-9954-eeab8217a8d3",
"name": "Default",
"hasThumbnail": "true",
"role": "3d",
"camera": [-86.09573364257812, -79.89456176757812, 139.12220764160156, 70.56798553466797, 76.76915740966797, -17.541505813598633, 0.40824830532073975, 0.40824830532073975, 0.8164966106414795, 1.664323329925537, 0.785398006439209, 1, 0],
"useAsDefault": true,
"status": "success",
"type": "view",
"children": [{
"guid": "f2054c5f-10b8-457b-a927-23b69107dcd7",
"role": "thumbnail",
"mime": "image/png",
"resolution": [100, 100],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/0_100.png",
"type": "resource"
}, {
"guid": "20625548-d014-4d29-8e50-4d61a1759a60",
"role": "thumbnail",
"mime": "image/png",
"resolution": [200, 200],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/0_200.png",
"type": "resource"
}, {
"guid": "48675a6a-f2ec-4748-b22c-200b72cd06a8",
"role": "thumbnail",
"mime": "image/png",
"resolution": [400, 400],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/0_400.png",
"type": "resource"
}]
}, {
"guid": "77850512-9e8b-4d09-bb1a-45706ad5b7e6",
"name": "3D View",
"hasThumbnail": "false",
"role": "viewable",
"progress": "0% complete",
"status": "success",
"type": "folder",
"children": [{
"guid": "ebf9f756-6cfa-4858-9787-e3af9c8424c3",
"name": "3D Duct & Equipment",
"role": "3d",
"camera": [61.56271743774414, 38.53883743286133, 9.783880233764648, 59.46215057373047, 40.639404296875, 7.683313846588135, -0.40824830532073975, 0.40824830532073975, 0.8164966106414795, 1, 45, 227.96743774414062, 1],
"status": "success",
"type": "view"
}, {
"guid": "54d5a270-f330-4446-a482-1079312d8518",
"name": "Main Electrical Distribution",
"role": "3d",
"camera": [91.54497528076172, -63.42673110961914, -34.64605712890625, 46.680015563964844, 38.5232048034668, -66.7026596069336, -0.11140129715204239, 0.25314533710479736, 0.9609928131103516, 1, 45, 342.1146545410156, 1],
"status": "success",
"type": "view"
}, {
"guid": "2c6938f2-c052-4195-93d0-adc7af1cb965",
"name": "3D Plumbing",
"role": "3d",
"camera": [3.6063644886016846, -184.62478637695312, 180.24473571777344, 173.09983825683594, -2.4171712398529053, -0.014680136926472187, 0.39955270290374756, 0.42952418327331543, 0.8098559379577637, 1, 45, 461.8291931152344, 1],
"status": "success",
"type": "view"
}, {
"guid": "1b3f6ae4-beb6-478c-9cfe-b83bf371141d",
"name": "Room 53 3D Fire Protection",
"role": "3d",
"camera": [735.119384765625, -538.998779296875, 662.6300048828125, 98.2931900024414, 97.82740020751953, 25.80381202697754, -0.40824830532073975, 0.40824830532073975, 0.8164966106414795, 1, 45, 368.90972900390625, 1],
"status": "success",
"type": "view"
}, {
"guid": "45811cc4-79ed-421b-82b2-6c8548d1507e",
"name": "WSHP 2-3 System View",
"role": "3d",
"camera": [108.588134765625, 117.7073974609375, 54.383365631103516, 102.33130645751953, 123.9642333984375, 48.12653350830078, -0.40824830532073975, 0.40824830532073975, 0.8164966106414795, 1, 45, 333.1808776855469, 1],
"status": "success",
"type": "view"
}, {
"guid": "8c1402a9-6af6-47af-af0d-2c025ca26109",
"name": "Plumbing Isometric - Domestic Water",
"role": "3d",
"camera": [3.6063644886016846, -184.62478637695312, 180.24473571777344, 173.09983825683594, -2.4171712398529053, -0.014680136926472187, 0.39955270290374756, 0.42952418327331543, 0.8098559379577637, 1, 45, 461.8291931152344, 1],
"status": "success",
"type": "view"
}, {
"guid": "9dcc0f6a-fc2c-418f-8d08-c99b7afed337",
"name": "Plumbing Isometric - Sanitary Waste",
"role": "3d",
"camera": [3.6063644886016846, -184.62478637695312, 180.24473571777344, 173.09983825683594, -2.4171712398529053, -0.014680136926472187, 0.39955270290374756, 0.42952418327331543, 0.8098559379577637, 1, 45, 461.8291931152344, 1],
"status": "success",
"type": "view"
}, {
"guid": "e3a2443a-7f4c-49dc-a41d-da067922ab04",
"name": "Typical Make Up Air Isometric Detail",
"role": "3d",
"camera": [0.8279496431350708, 187.99771118164062, 118.81455993652344, 100.31283569335938, 88.51282501220703, 19.32967758178711, 0.40824830532073975, -0.40824830532073975, 0.8164966106414795, 1, 45, 248.74505615234375, 1],
"status": "success",
"type": "view"
}, {
"guid": "915564b9-ed83-426e-88df-002dac32363b",
"name": "Typical Room WSHP",
"role": "3d",
"camera": [171.6078338623047, -3.038959264755249, 18.71452522277832, 90.31718444824219, 43.15993118286133, -21.66922950744629, -0.34472253918647766, 0.19591180980205536, 0.9180331826210022, 1, 45, 257.0640869140625, 1],
"status": "success",
"type": "view"
}, {
"guid": "12a3ef04-1364-4c23-af91-2679132e3848",
"name": "Toilet Room",
"role": "3d",
"camera": [196.7369842529297, -4.305071830749512, 109.12708282470703, 98.9510269165039, 86.86759948730469, 14.070858001708984, -0.42381933331489563, 0.3951563239097595, 0.8150022625923157, 1, 45, 359.9964294433594, 1],
"status": "success",
"type": "view"
}, {
"guid": "9a34ab86-dfdf-4516-a087-b8f9775435fe",
"name": "1st Level Slice",
"role": "3d",
"camera": [-76.2143325805664, -163.60708618164062, 175.46923828125, 111.73212432861328, 69.6202392578125, 11.465206146240234, 0.3013473451137543, 0.373949259519577, 0.8771269917488098, 1, 45, 313.0205993652344, 1],
"status": "success",
"type": "view"
}, {
"guid": "09effac0-27ac-4f02-b4d7-31ef18a57ef9",
"name": "{3D}",
"role": "3d",
"camera": [0.8279496431350708, 187.99771118164062, 118.81455993652344, 100.31283569335938, 88.51282501220703, 19.32967758178711, 0.40824830532073975, -0.40824830532073975, 0.8164966106414795, 1, 45, 358.7159118652344, 1],
"status": "success",
"type": "view"
}]
}, {
"guid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"role": "graphics",
"mime": "application/autodesk-svf",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/0.svf",
"type": "resource"
}]
}, {
"guid": "3b7195a7-17ec-4d80-b259-4e9df165f3fb",
"role": "Autodesk.CloudPlatform.PropertyDatabase",
"mime": "application/autodesk-db",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/properties.db",
"status": "success",
"type": "resource"
}]
}, {
"hasThumbnail": "false",
"status": "success",
"progress": "complete",
"outputType": "obj",
"children": [{
"guid": "22519ef5-9da5-35ca-bc70-b25b45e8f8fa",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [547, 924, 942, 977],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/e72fa6b3-4fc2-3c86-8424-5d0755539c0d.obj",
"status": "success",
"type": "resource"
}, {
"guid": "75401422-bb33-350a-aa10-05625504d6ca",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [547, 924, 942, 977],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/e72fa6b3-4fc2-3c86-8424-5d0755539c0d.mtl",
"status": "success",
"type": "resource"
}, {
"guid": "a4b9fb43-8525-3243-bde1-72797399e342",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [547, 924, 942, 977],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/e72fa6b3-4fc2-3c86-8424-5d0755539c0d.zip",
"status": "success",
"type": "resource"
}, {
"guid": "1177e7ea-7fad-34b7-a7bd-23d70e4a62a8",
"type": "resource",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [17, 19, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 263, 264, 265, 268, 269, 270, 302, 303, 304, 320, 321, 322, 350, 351, 352, 370, 371],
"status": "success",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/a08e65e7-082a-3ce1-8116-ae534c9f081d.obj"
}, {
"guid": "61acd067-4637-3549-9bd3-cd362a4fb93b",
"type": "resource",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [17, 19, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 263, 264, 265, 268, 269, 270, 302, 303, 304, 320, 321, 322, 350, 351, 352, 370, 371],
"status": "success",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/a08e65e7-082a-3ce1-8116-ae534c9f081d.mtl"
}, {
"guid": "6c73254c-7bbf-312a-a481-aaeebdf53de3",
"type": "resource",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [17, 19, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 263, 264, 265, 268, 269, 270, 302, 303, 304, 320, 321, 322, 350, 351, 352, 370, 371],
"status": "success",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/a08e65e7-082a-3ce1-8116-ae534c9f081d.zip"
}]
}]
}
Use GET :urn/metadata to obtain a list of model views:
{
"data": {
"type": "metadata",
"metadata": [
{
"name": "Scene",
"role": "3d",
"guid": "4f981e94-8241-4eaf-b08b-cd337c6b8b1f",
},
{
"name": "Sheet: A101",
"role": "2d",
"guid": "8e7c6bca-cfd1-290e-4b16-f3670169bb71"
}
]
}
}
Then use GET :urn/metadata/:guid to retrieve the object tree to identify your derivatives:
{
"data": {
"type": "objects",
"objects": [
{
"objectid": 1,
"name": "A5",
"objects": [
{
"objectid": 2,
"name": "Model",
"objects": [
{
"objectid": 3,
"name": "Bottom",
"objects": [
{
"objectid": 4,
"name": "Box"
}
]
},

How can I sort data with Firebase?

I am creating a little React application about Pokemons. I have in DB informations about all of them (about 900+).
They all contain an id field, which is an integer from 1 to 900+.
But the problem is when I do a request like this :
firebase.database().ref(`mydb`).orderByChild('id').startAt(1).limitToFirst(limit).once('value')
The results are not correct: I have an id array like this: [9,1, 10, 6, 4]
Am I doing something wrong ?
Edit:
I add the result I got when I perform the request I wrote above, I added a custom_id field containing ids as strings, but I stille have an unordered result:
[
{
"base_experience": 239,
"custom_id": "009",
"height": 16,
"id": 9,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/9/encounters",
"name": "blastoise",
"order": 12,
"weight": 855
},
{
"base_experience": 64,
"custom_id": "001",
"height": 7,
"id": 1,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/1/encounters",
"name": "bulbasaur",
"order": 1,
"weight": 69
},
{
"base_experience": 39,
"custom_id": "010",
"height": 3,
"id": 10,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/10/encounters",
"name": "caterpie",
"order": 14,
"weight": 29
},
{
"base_experience": 240,
"custom_id": "006",
"height": 17,
"id": 6,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/6/encounters",
"name": "charizard",
"order": 7,
"weight": 905
},
{
"base_experience": 62,
"custom_id": "004",
"height": 6,
"id": 4,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/4/encounters",
"name": "charmander",
"order": 5,
"weight": 85
},
{
"base_experience": 142,
"custom_id": "005",
"height": 11,
"id": 5,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/5/encounters",
"name": "charmeleon",
"order": 6,
"weight": 190
},
{
"base_experience": 142,
"custom_id": "002",
"height": 10,
"id": 2,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/2/encounters",
"name": "ivysaur",
"order": 2,
"weight": 130
},
{
"base_experience": 63,
"custom_id": "007",
"height": 5,
"id": 7,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/7/encounters",
"name": "squirtle",
"order": 10,
"weight": 90
},
{
"base_experience": 236,
"custom_id": "003",
"height": 20,
"id": 3,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/3/encounters",
"name": "venusaur",
"order": 3,
"weight": 1000
},
{
"base_experience": 142,
"custom_id": "008",
"height": 10,
"id": 8,
"is_default": true,
"location_area_encounters": "https://pokeapi.co/api/v2/pokemon/8/encounters",
"name": "wartortle",
"order": 11,
"weight": 225
}
]
You've not attached your database image, but with the order one thing is sure that these keys in your database are strings.
And when you order string data, it is ordered lexicographically.
So for numbers, this is the normal order:
1
9
10
But for strings, this is the normal order:
"9"
"1"
"10"
I don't think there is any operator in Firebase (nor in most other databases) to change this behaviour.
Instead, you will have to modify the data to get the behavior you want. So: store values that are in the order you need them when sorted lexicographically.
For numbers you can accomplish that by padding them with zeroes:
"001"
"009"
"010"
EDIT:
Now after Json, these values are stored in id field so the above thing does not apply to this.
You may however use a code like this, to do what you're trying:
mDatabase
.child("main_child")
.orderByChild("id")
.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot child: snapshot.getChildren()) {
System.out.println(child.getKey());
}
}
...

Categories

Resources