Vue js: fetching Data from API - javascript

in my code below i'm showing data from API for all flats in one page, but i couldn't figure out how to show the floor_number in each flat, below is my JSON body :
{
"response": [
{
"floors": [
{
"flats": [
{
"status": "",
"price": "80000",
"currency": "USD",
"end_date": "Not Set",
"buyer": " ",
"buyer_phone_number": "07701879915",
"receipt_number_field": "058329",
"size_unit": "M",
"_id": "61e6bccba5da17be7a90fe2e",
"flat_number": 1,
"description": "This is a newly created flat.",
"city": "",
"payment": {
"installment_payment": {
"installments": [
{
"amount": "12000.00",
"date": "2022-02-12",
"is_paid": true
},
{
"amount": "12000.00",
"date": "2023-03-03",
"is_paid": false
},
{
"amount": "16000.00",
"date": "2023-08-19",
"is_paid": false
},
{
"amount": "0.00",
"date": "2022-02-20",
"is_paid": false
},
{
"amount": "342",
"date": "2022-03-12",
"is_paid": false
}
],
"remaining": "67316"
},
"paid_amount": "12684"
},
"floor": "61e6bccba5da17be7a90fe2d",
"building": "61e6bccba5da17be7a90fe2c",
"size": "176.25",
"directions": " ",
"createdAt": "2022-01-18T13:12:53.212Z",
"updatedAt": "2022-02-12T12:19:43.862Z",
"__v": 0
},
{
"status": "",
"price": "Not set",
"currency": "USD",
"end_date": "2022-02-16",
"buyer": "Not Set",
"buyer_phone_number": "Not Set",
"receipt_number_field": "Not Set",
"size_unit": "M",
"_id": "61e6bccba5da17be7a90fe2f",
"flat_number": 2,
"description": "This is a newly created flat.",
"city": "",
"floor": "61e6bccba5da17be7a90fe2d",
"building": "61e6bccba5da17be7a90fe2c",
"size": "176.25",
"directions": " ",
"createdAt": "2022-01-18T13:12:53.446Z",
"updatedAt": "2022-02-13T07:42:26.750Z",
"__v": 0
},
{
"status": "",
"price": "27441",
"currency": "USD",
"end_date": "2022-02-17",
"buyer": "new",
"buyer_phone_number": "7544112",
"receipt_number_field": "0432516",
"size_unit": "M",
"_id": "61e6bccba5da17be7a90fe30",
"flat_number": 3,
"description": "This is a newly created flat.",
"city": "",
"floor": "61e6bccba5da17be7a90fe2d",
"building": "61e6bccba5da17be7a90fe2c",
"size": "132",
"directions": "",
"createdAt": "2022-01-18T13:12:53.447Z",
"updatedAt": "2022-02-14T15:18:33.228Z",
"__v": 0
},
{
"status": "",
"price": "Not set",
"currency": "USD",
"end_date": "Not Set",
"buyer": "Not Set",
"buyer_phone_number": "Not Set",
"receipt_number_field": "Not Set",
"size_unit": "M",
"_id": "61e6bccba5da17be7a90fe31",
"flat_number": 4,
"description": "This is a newly created flat.",
"city": "",
"payment": null,
"floor": "61e6bccba5da17be7a90fe2d",
"building": "61e6bccba5da17be7a90fe2c",
"size": "184",
"directions": " ",
"createdAt": "2022-01-18T13:12:53.447Z",
"updatedAt": "2022-01-18T13:12:53.447Z",
"__v": 0
},
{
"status": "",
"price": "Not set",
"currency": "USD",
"end_date": "Not Set",
"buyer": "Not Set",
"buyer_phone_number": "Not Set",
"receipt_number_field": "Not Set",
"size_unit": "M",
"_id": "61e6bccba5da17be7a90fe32",
"flat_number": 5,
"description": "This is a newly created flat.",
"city": "",
"payment": null,
"floor": "61e6bccba5da17be7a90fe2d",
"building": "61e6bccba5da17be7a90fe2c",
"size": "184",
"directions": " ",
"createdAt": "2022-01-18T13:12:53.447Z",
"updatedAt": "2022-01-18T13:12:53.447Z",
"__v": 0
},
{
"status": "ava",
"price": "Not set",
"currency": "USD",
"end_date": "Not Set",
"buyer": "Not Set",
"buyer_phone_number": "Not Set",
"receipt_number_field": "Not Set",
"size_unit": "M",
"_id": "61e6bccba5da17be7a90fe33",
"flat_number": 6,
"description": "This is a newly created flat.",
"city": "city",
"payment": null,
"floor": "61e6bccba5da17be7a90fe2d",
"building": "61e6bccba5da17be7a90fe2c",
"size": "132",
"directions": "south",
"createdAt": "2022-01-18T13:12:53.447Z",
"updatedAt": "2022-02-12T17:31:21.171Z",
"__v": 0
}
],
"_id": "61e6bccba5da17be7a90fe2d",
"floor_number": 1,
"description": "This is a newly created floor.",
"createdAt": "2022-01-18T13:12:53.447Z",
"updatedAt": "2022-01-18T13:12:53.447Z",
"__v": 0
},
P.s: i have 6 flats in each floor
<b-card-body class="px-lg-5 py-lg-5" v-for="flat in flats" :key="flat._id"> // flats API where i have all flats
<div class="text-center text-muted mb-4 border-dash">
<p class="city">{{flat.city}}</p>
<span v-for="(building,index) in buildings" :key="index"> //JSOn body provided above
<p class="iconB" v-if="building._id.includes(flat.building)">{{building.building_number}} building number </p>
<h3>{{building.floor_number}} floor</h3> //not working
</span>
<h2>{{flat.buyer}} <i class="fas fa-user"></i> </h2>
<h3 class="mb-5">flat no ({{flat.flat_number}})</h3>
in my code above every thing is showing except the floor :\
any help?

I just tooked your code and passed it and all i did was this from your response array because your floor_number is not inside the flat but at the same level of it :
<div v-for="floor in floors">
{{floor.floor_number}}
</div>

Related

How to fitter one collection to another collection?

I am trying to filter one collection to another collection document I got all document not filter document
const getbookbycaterogry = async (req,res)=>{
let query = req.query
let filtercategory= await categoryModel.find({query:query}).select({_id:0})
console.log("filtercategory",filtercategory)
if(query.category){
let categoryquery = req.query
let getcategorydetail = await categoryModel.findOne({categoryquery:categoryquery})
if(!getcategorydetail){
res.send({status:false,message:"this category book not present here"})
}
}
let bookdetail = await BookModel.find({})
const obj = {
filtercategory :filtercategory ,
bookdetail :bookdetail
}
res.send({status:true,message:"book detail get sucessfully",obj})
}
I get this output
{
"obj": {
"filtercategory": [
{
"category": "Biography",
"ISBN": 8185301417,
"createdAt": "2023-02-03T06:51:30.812Z",
"updatedAt": "2023-02-03T06:51:30.812Z",
"__v": 0
},
{
"category": "novel",
"ISBN": 8129135728,
"createdAt": "2023-02-03T06:52:12.488Z",
"updatedAt": "2023-02-03T06:52:12.488Z",
"__v": 0
},
{
"category": "novel",
"ISBN": 8129135515,
"createdAt": "2023-02-03T06:53:05.231Z",
"updatedAt": "2023-02-03T06:53:05.231Z",
"__v": 0
}
],
"bookdetail": [
{
"_id": "63dc99c66db9935e48a3a07f",
"authorName": "chetan bhagat",
"tittle": "half girlfriend",
"category": "novel",
"subcategory": [
"love story of bihari boy"
],
"Nopages": 280,
"ISBN": 8129135728,
"price": 400,
"currency": "rs",
"publisherBy": "Rupa & Co.",
"publishedDate": "2023-02-04T18:30:00.000Z",
"isDeleted": false,
"createdAt": "2023-02-03T05:21:10.084Z",
"updatedAt": "2023-02-03T05:21:10.084Z",
"__v": 0
},
{
"_id": "63dc9ac46db9935e48a3a081",
"authorName": "chetan bhagat",
"tittle": "3 mistake of my life",
"category": "novel",
"subcategory": [
"3 friend stroty"
],
"Nopages": 280,
"ISBN": 8129135515,
"price": 300,
"currency": "rs",
"publisherBy": "aryan",
"publishedDate": "2023-02-04T18:30:00.000Z",
"isDeleted": false,
"createdAt": "2023-02-03T05:25:24.287Z",
"updatedAt": "2023-02-03T05:25:24.287Z",
"__v": 0
},
{
"_id": "63dc9b596db9935e48a3a083",
"authorName": "A. P. J. Abdul Kalam",
"tittle": "Wings of Fire",
"category": "novel",
"subcategory": [
"story about life of A. P. J. Abdul Kalam"
],
"Nopages": 380,
"ISBN": 9788173711466,
"price": 350,
"currency": "rs",
"publisherBy": "Sangam Books Ltd.",
"publishedDate": "2023-02-04T00:00:00.000Z",
"isDeleted": false,
"createdAt": "2023-02-03T05:27:53.229Z",
"updatedAt": "2023-02-03T05:27:53.229Z",
"__v": 0
},
{
"_id": "63dc9c466db9935e48a3a085",
"authorName": "Ikigai",
"tittle": "secrets to a happy life",
"category": "motivation",
"subcategory": [
"story about how can we make life happy"
],
"Nopages": 120,
"ISBN": 764211242,
"price": 1080,
"currency": "rs",
"publisherBy": "aryan Books Ltd.",
"publishedDate": "2023-02-04T00:00:00.000Z",
"isDeleted": false,
"createdAt": "2023-02-03T05:31:50.668Z",
"updatedAt": "2023-02-03T05:31:50.668Z",
"__v": 0
},
{
"_id": "63dc9d256db9935e48a3a087",
"authorName": "Swami Nikhilananda",
"tittle": "Vivekananda:A Biography",
"category": "Biography",
"subcategory": [
"story about life of Swami Nikhilananda"
],
"Nopages": 320,
"ISBN": 8185301417,
"price": 980,
"currency": "rs",
"publisherBy": "Advaita Ashrama, India",
"publishedDate": "2023-02-04T00:00:00.000Z",
"isDeleted": false,
"createdAt": "2023-02-03T05:35:33.208Z",
"updatedAt": "2023-02-03T05:35:33.208Z",
"__v": 0
}
]
}
}
But I want an output like this: If I have searched for novel, then I get all books in the novel category
{
"obj": {
"filtercategory": [
{
"category": "novel"
}
],
"bookdetail": [
{
"_id": "63dc99c66db9935e48a3a07f",
"authorName": "chetan bhagat",
"tittle": "half girlfriend",
"category": "novel",
"subcategory": [
"love story of bihari boy"
],
"Nopages": 280,
"ISBN": 8129135728,
"price": 400,
"currency": "rs",
"publisherBy": "Rupa & Co.",
"publishedDate": "2023-02-04T18:30:00.000Z",
"isDeleted": false,
"createdAt": "2023-02-03T05:21:10.084Z",
"updatedAt": "2023-02-03T05:21:10.084Z",
"__v": 0
},
{
"_id": "63dc9ac46db9935e48a3a081",
"authorName": "chetan bhagat",
"tittle": "3 mistake of my life",
"category": "novel",
"subcategory": [
"3 friend stroty"
],
"Nopages": 280,
"ISBN": 8129135515,
"price": 300,
"currency": "rs",
"publisherBy": "aryan",
"publishedDate": "2023-02-04T18:30:00.000Z",
"isDeleted": false,
"createdAt": "2023-02-03T05:25:24.287Z",
"updatedAt": "2023-02-03T05:25:24.287Z",
"__v": 0
},
{
"_id": "63dc9b596db9935e48a3a083",
"authorName": "A. P. J. Abdul Kalam",
"tittle": "Wings of Fire",
"category": "novel",
"subcategory": [
"story about life of A. P. J. Abdul Kalam"
],
"Nopages": 380,
"ISBN": 9788173711466,
"price": 350,
"currency": "rs",
"publisherBy": "Sangam Books Ltd.",
"publishedDate": "2023-02-04T00:00:00.000Z",
"isDeleted": false,
"createdAt": "2023-02-03T05:27:53.229Z",
"updatedAt": "2023-02-03T05:27:53.229Z",
"__v": 0
}
]
}
}
So got out as like one my collection book and another collection category so if I am filter data collection by category.
You need to check category in the Book Model only like
const getbookbycaterogry = async (req, res) => {
const { category } = req.query
if (!category) {
return res.status(400).send({ status: false, message: "Please add category" });
}
const categoryFilter = { category };
const bookdetail = await BookModel.find(categoryFilter)
if (bookdetail.length) {
const obj = {
filtercategory: categoryFilter,
bookdetail: bookdetail
}
res.send({ status: true, message: "book detail get sucessfully", obj });
} else {
res.send({ status: false, message: "this category book not present here" });
}
}

How to update a field inside the array of object of another array of objects in mongo db? or How to update a field using the array index in mongo db?

This is the structure of my collection of mongodb database. I need to update the status inside each order products. What I need to do?
{
"_id": {
"$oid": "633ab3c11e6e97b6332f56a1"
},
"orders": [
{
"date": "6/10/2022",
"productDetails": {
"0": {
"name": "Top",
"price": "1235",
"quantity": 1,
"status": "placed"
},
"1": {
"name": "Shirt",
"price": "1235",
"quantity": 1,
"status": "placed"
}
},
"billingAddress": {
"address": "My Address",
"city": "City",
"state": "State",
"country": "Country",
"pincode": "123456",
"contact": "1234567890"
},
"paymentMode": "cod"
},
{
"date": "6/10/2022",
"productDetails": {
"0": {
"name": "Top",
"price": "1235",
"quantity": 3,
"status": "placed"
},
"1": {
"name": "Shirt",
"price": "1235",
"quantity": 1,
"status": "placed"
}
},
"billingAddress": {
"address": "My Address",
"city": "City",
"state": "State",
"country": "Country",
"pincode": "123456",
"contact": "1234567890"
},
"paymentMode": "cod"
},
{
"date": "6/10/2022",
"productDetails": {
"0": {
"name": "Shirt",
"price": "234",
"quantity": 1,
"status": "placed"
},
"1": {
"name": "Top",
"price": "123",
"quantity": 1,
"status": "placed"
}
},
"billingAddress": {
"address": "My Address",
"city": "City",
"state": "State",
"country": "Country",
"pincode": "123456",
"contact": "1234567890"
},
"paymentMode": "cod"
}
]
}
I want to update the order product status to shipped, canceled, etc. I have to set status in desired position like the following.
I waant to update the mongodb databse and have to get the result in like the following result.
{
"_id": {
"$oid": "633ab3c11e6e97b6332f56a1"
},
"orders": [
{
"date": "6/10/2022",
"productDetails": {
"0": {
"name": "Top",
"price": "1235",
"quantity": 1,
"status": "caneled"
},
"1": {
"name": "Shirt",
"price": "1235",
"quantity": 1,
"status": "shipped"
}
},
"billingAddress": {
"address": "My Address",
"city": "City",
"state": "State",
"country": "Country",
"pincode": "123456",
"contact": "1234567890"
},
"paymentMode": "cod"
},
{
"date": "6/10/2022",
"productDetails": {
"0": {
"name": "Top",
"price": "1235",
"quantity": 3,
"status": "canceled"
},
"1": {
"name": "Shirt",
"price": "1235",
"quantity": 1,
"status": "shipped"
}
},
"billingAddress": {
"address": "My Address",
"city": "City",
"state": "State",
"country": "Country",
"pincode": "123456",
"contact": "1234567890"
},
"paymentMode": "cod"
},
{
"date": "6/10/2022",
"productDetails": {
"0": {
"name": "Shirt",
"price": "234",
"quantity": 1,
"status": "placed"
},
"1": {
"name": "Top",
"price": "123",
"quantity": 1,
"status": "shipped"
}
},
"billingAddress": {
"address": "My Address",
"city": "City",
"state": "State",
"country": "Country",
"pincode": "123456",
"contact": "1234567890"
},
"paymentMode": "cod"
}
]
}
According to my research, the correct method is as follows:
db.orders.updateOne({_id: ObjectId("633a6a73dd9f8cce0029e53d")},{$set:{"orders.0.productDetails.0.status": "shipped"}})
And the result is :-
{
"_id": {
"$oid": "633ab3c11e6e97b6332f56a1"
},
"orders": [
{
"_id": {
"$oid": "633e8f2d3e3f12f07438cc64"
},
"date": "6/10/2022",
"productDetails": {
"0": {
"name": "Top",
"price": "1235",
"quantity": 1,
"status": "shipped"
},
"1": {
"name": "Shirt",
"price": "1235",
"quantity": 1,
"status": "placed"
}
},
"billingAddress": {
"address": "My Address",
"city": "City",
"state": "State",
"country": "Country",
"pincode": "123456",
"contact": "1234567890"
},
"paymentMode": "cod"
},
{
"_id": {
"$oid": "633e96533e3f12f07438cc65"
},
"date": "6/10/2022",
"productDetails": {
"0": {
"name": "Top",
"price": "1235",
"quantity": 1,
"status": "placed"
},
"1": {
"name": "Shirt",
"price": "1235",
"quantity": 1,
"status": "placed"
},
"2": {
"name": "Jeans",
"price": "1234",
"quantity": 1,
"status": "placed"
}
},
"billingAddress": {
"address": "My Address",
"city": "City",
"state": "State",
"country": "Country",
"pincode": "123456",
"contact": "1234567890"
},
"paymentMode": "cod"
}
]
}

item_option_selection - Where to put in the json request?

I see in the documentation that there's a way to set item options: https://developer.paypal.com/docs/api/payments/#definition-item_option_selection
Where do i exactly put this in paypal example? I don't find examples or any instruction on paypal developers documentation
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "30.11",
"currency": "USD",
"details": {
"subtotal": "30.00",
"tax": "0.07",
"shipping": "0.03",
"handling_fee": "1.00",
"shipping_discount": "-1.00",
"insurance": "0.01"
}
},
"description": "The payment transaction description.",
"custom": "EBAY_EMS_90048630024435",
"invoice_number": "48787589673",
"payment_options": {
"allowed_payment_method": "INSTANT_FUNDING_SOURCE"
},
"soft_descriptor": "ECHI5786786",
"item_list": {
"items": [
{
"name": "hat",
"description": "Brown hat.",
"quantity": "5",
"price": "3",
"tax": "0.01",
"sku": "1",
"currency": "USD"
},
{
"name": "handbag",
"description": "Black handbag.",
"quantity": "1",
"price": "15",
"tax": "0.02",
"sku": "product34",
"currency": "USD"
}
],
"shipping_address": {
"recipient_name": "Brian Robinson",
"line1": "4th Floor",
"line2": "Unit #34",
"city": "San Jose",
"country_code": "US",
"postal_code": "95131",
"phone": "011862212345678",
"state": "CA"
}
}
}
],
"note_to_payer": "Contact us for any questions on your order.",
"redirect_urls": {
"return_url": "https://www.paypal.com/return",
"cancel_url": "https://www.paypal.com/cancel"
}
}'
The object is not part of the Paypal REST api anymore. It will be removed soon
Reference: https://github.com/paypal/PayPal-REST-API-issues/issues/137

angularjs 1.x filter for array type

I have lot of objects like below in array now i want to apply filter on it. How i can apply filter like i have mention in image:
Can i use simple AngularJS filter on it?
Kindly help me with best approach to apply these filter. Thanks in advance. I have multiple hotels data like that in this JSON. But I am not butting it all because of space.
[
{
"_id": "57da6aeb4eafac04afd01bc5",
"name": "subways",
"city": "lahore",
"area": "johar town",
"min_order": "200 AED",
"del_time": "1 hour",
"del_fees": "1 AED",
"pre_order": "NA",
"rating_star": "4",
"rating_no": 514,
"status": "OPEN",
"__v": 0,
"categories": [
{
"_id": "57da72e94eafac04afd01bc9",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"name": "subways Burger",
"category_id": "1",
"__v": 0,
"items": [
{
"_id": "57da7973d0b5e2059c5ff10a",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 1",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
},
{
"_id": "57da79e8d0b5e2059c5ff10b",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 2",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
},
{
"_id": "57da79efd0b5e2059c5ff10c",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 3",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
},
{
"_id": "57da79fcd0b5e2059c5ff10d",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 4",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}
]
}
]
A simple AngularJS filter to handle such operations is shown below:
angular.module("myapp", [])
.controller("myctrl", function myctrl($scope) {
$scope.cityIncludes = [];
$scope.includeCity = function(city) {
console.log( city );
var i = $scope.cityIncludes.indexOf(city);
if (i > -1) {
$scope.cityIncludes.splice(i, 1);
} else {
$scope.cityIncludes.push(city);
}
console.log( $scope.cityIncludes);
}
$scope.cityFilter = function(city) {
if ($scope.cityIncludes.length > 0) {
if ($scope.cityIncludes.indexOf(city.city) < 0)
return;
}
return city;
}
$scope.rests = [{
"_id": "57da6aeb4eafac04afd01bc5",
"name": "Lahore Restaurant",
"city": "lahore",
"area": "johar town",
"min_order": "200 AED",
"del_time": "1 hour",
"del_fees": "1 AED",
"pre_order": "NA",
"rating_star": "4",
"rating_no": 514,
"status": "OPEN",
"__v": 0,
"categories": [{
"_id": "57da72e94eafac04afd01bc9",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"name": "subways Burger",
"category_id": "1",
"__v": 0,
"items": [{
"_id": "57da7973d0b5e2059c5ff10a",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 1",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79e8d0b5e2059c5ff10b",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 2",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79efd0b5e2059c5ff10c",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 3",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79fcd0b5e2059c5ff10d",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 4",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}]
}]
}, {
"_id": "57da6aeb4eafac04afd01bc5",
"name": "islamabad rest",
"city": "islamabad",
"area": "johar town",
"min_order": "200 AED",
"del_time": "1 hour",
"del_fees": "1 AED",
"pre_order": "NA",
"rating_star": "4",
"rating_no": 514,
"status": "OPEN",
"__v": 0,
"categories": [{
"_id": "57da72e94eafac04afd01bc9",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"name": "subways Burger",
"category_id": "1",
"__v": 0,
"items": [{
"_id": "57da7973d0b5e2059c5ff10a",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 1",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79e8d0b5e2059c5ff10b",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 2",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79efd0b5e2059c5ff10c",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 3",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79fcd0b5e2059c5ff10d",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 4",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}]
}]
}, {
"_id": "57da6aeb4eafac04afd01bc5",
"name": "abcd",
"city": "rawalpindi",
"area": "johar town",
"min_order": "200 AED",
"del_time": "1 hour",
"del_fees": "1 AED",
"pre_order": "NA",
"rating_star": "4",
"rating_no": 514,
"status": "OPEN",
"__v": 0,
"categories": [{
"_id": "57da72e94eafac04afd01bc9",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"name": "subways Burger",
"category_id": "1",
"__v": 0,
"items": [{
"_id": "57da7973d0b5e2059c5ff10a",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 1",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79e8d0b5e2059c5ff10b",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 2",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79efd0b5e2059c5ff10c",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 3",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79fcd0b5e2059c5ff10d",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 4",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}]
}]
}, {
"_id": "57da6aeb4eafac04afd01bc5",
"name": "asdadsasdasdas",
"city": "karachi",
"area": "johar town",
"min_order": "200 AED",
"del_time": "1 hour",
"del_fees": "1 AED",
"pre_order": "NA",
"rating_star": "4",
"rating_no": 514,
"status": "OPEN",
"__v": 0,
"categories": [{
"_id": "57da72e94eafac04afd01bc9",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"name": "subways Burger",
"category_id": "1",
"__v": 0,
"items": [{
"_id": "57da7973d0b5e2059c5ff10a",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 1",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79e8d0b5e2059c5ff10b",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 2",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79efd0b5e2059c5ff10c",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 3",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79fcd0b5e2059c5ff10d",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 4",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}]
}]
}, {
"_id": "57da6aeb4eafac04afd01bc5",
"name": "multan asdasda",
"city": "multan",
"area": "johar town",
"min_order": "200 AED",
"del_time": "1 hour",
"del_fees": "1 AED",
"pre_order": "NA",
"rating_star": "4",
"rating_no": 514,
"status": "OPEN",
"__v": 0,
"categories": [{
"_id": "57da72e94eafac04afd01bc9",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"name": "subways Burger",
"category_id": "1",
"__v": 0,
"items": [{
"_id": "57da7973d0b5e2059c5ff10a",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 1",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79e8d0b5e2059c5ff10b",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 2",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79efd0b5e2059c5ff10c",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 3",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}, {
"_id": "57da79fcd0b5e2059c5ff10d",
"restaurant_id": "57da6aeb4eafac04afd01bc5",
"category_id": "57da72e94eafac04afd01bc9",
"logo": "abcLogo",
"name": "subway item 4",
"detail": "great item",
"price": "10",
"rating": "5",
"__v": 0
}]
}]
}]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myapp" ng-controller="myctrl">
<ul>
<li ng-repeat="rest in rests track by rest.city">
<input name="rest.city" type="checkbox" value="rest.city" ng-click="includeCity(rest.city)">
<label for="rest.city">{{rest.city}}</label>
</li>
</ul>
<ul>
<li ng-repeat="rest in rests | filter: cityFilter">
<p ng-bind="rest.name"></p>
<p ng-bind="'Rating ' + rest.rating_star"></p>
<p ng-bind="'Status ' + rest.status"></p>
<p ng-bind="'Area ' + rest.area"></p>
</li>
</ul>
</body>
You can use this concept.
i have done
i have radio box for all type of cuisines when any one select. i save it into scope type variable with below function. now question is how i filter it bro.
<ul>
<li>
<input name="rest.cusine" type="radio" value="india" ng-click="filterCuisine('indian')">
<label for="open status">india</label>
</li>
<li>
<input name="rest.cusine" type="radio" value="india" ng-click="filterCuisine('pakistani')">
<label for="open status">pakistan</label>
</li>
<li>
<input name="rest.cusine" type="radio" value="arabic" ng-click="filterCuisine('arabic')">
<label for="open status">arabic</label>
</li>
</ul>
Function for getting the selected cuisine
$scope.filterCuisine = function(cuisine){
$scope.checkFilterCuisine = cuisine;
console.log($scope.checkFilterCuisine);
}
how i apply filter on this function
$scope.selectCuisine = function(city){
console.log(city.cuisines);
if (city.cuisines.length > 0 && $scope.checkFilterCuisine != '') {
if (city.cuisines.indexOf($scope.checkFilterCuisine) < 0){
return;
}
}
return city;
}

reformat json in desired format

{
"EUR": {
"Description": "",
"Bid": "1.1222",
"Region": "",
"Bid1": "1.1283",
"CurrencyCode": "EUR",
"FeedSource": "1",
"Ask": "1.1226",
"ProviderName": "TEST 1",
"Low": "1.1195",
"LastModified": "2014-05-20T08:11:13",
"CreatedBy": "10000",
"OpenBid": "1.12",
"QuotedCurrencyCode": "USD"
},
"PHP": {
"Description": "",
"Bid": "46.75",
"Region": "",
"Bid1": "4.59",
"CurrencyCode": "PHP",
"FeedSource": "1",
"Ask": "46.755",
"ProviderName": "Test2",
"Low": "4.715",
"LastModified": "2016-05-20T07:54:32",
"CreatedBy": "10000",
"QuotedCurrencyCode": "USD"
}
}
Need to reformat this json in below format,
{ CurrencyCode: "EUR", LastModified: "10/02/2012", ProviderName: "Test1", Bid: "1.2", Bid1: "1.19", Bid2: "1.2", Ask: "2CloseBid: "32", CloseAsk: "35" },
{ CurrencyCode: "PHP", LastModified: "10/02/2012", ProviderName: "Test2", Other fields... }]
I want to do this conversion in javascript.
Tried with stringify and parse but it doesn't give desired output.
Please suggest
You can use for-in loop & iterate over each key
let input = {
"EUR": {
"Description": "",
"Bid": "1.1222",
"Region": "",
"Bid1": "1.1283",
"CurrencyCode": "EUR",
"FeedSource": "1",
"Ask": "1.1226",
"ProviderName": "TEST 1",
"Low": "1.1195",
"LastModified": "2014-05-20T08:11:13",
"CreatedBy": "10000",
"OpenBid": "1.12",
"QuotedCurrencyCode": "USD"
},
"PHP": {
"Description": "",
"Bid": "46.75",
"Region": "",
"Bid1": "4.59",
"CurrencyCode": "PHP",
"FeedSource": "1",
"Ask": "46.755",
"ProviderName": "Test2",
"Low": "4.715",
"LastModified": "2016-05-20T07:54:32",
"CreatedBy": "10000",
"QuotedCurrencyCode": "USD"
}
}
var output = [];
for(let key in input){
output.push(input[key])
}
console.log(output);

Categories