0

In my travel website (just like airbnb ), user can sort record by Availability ,Price ,Location etc...

My website data ( record ) , where in json format only.I can't fetch record from the database.

My Data Record :

var json = [
        {"id":"1","tagName":"apple",'lat':"37.764121333563985","lng":"-122.43083545083414",'cat':'bus','price':50},
        {"id":"2","tagName":"orange",'lat':"37.760390258066806","lng":"-122.40842161915589",'cat':'bus','price':50},
        {"id":"3","tagName":"banana",'lat':"37.76821074033546","lng":"-122.39946165364097",'cat':'car','price':70},
        {"id":"4","tagName":"watermelon",'lat':"37.76903501995947","lng":"-122.43674595206681",'cat':'bus','price':50},
        {"id":"5","tagName":"pineapple",'lat':"37.775329253488984","lng":"-122.42896304538613",'cat':'car','price':50},
        {"id":"6","tagName":"pineapple",'lat':"37.76808825514635","lng":"-122.42957791610439",'cat':'bus','price':30},
        {"id":"7","tagName":"pineapple",'lat':"37.764609542480706","lng":"-122.43126917941493",'cat':'bus','price':50},
        {"id":"8","tagName":"pineapple",'lat':"37.77486256468261","lng":"-122.40143099838457",'cat':'car','price':20},
        {"id":"9","tagName":"pineapple",'lat':"37.770304718740945","lng":"-122.42489358892846",'cat':'bus','price':50},
        {"id":"10","tagName":"pineapple",'lat':"37.7628338732316","lng":"-122.42631843030665",'cat':'car','price':10}
    ];

My Javascript Code :

$(json).each(function(i,marker){
    if (cat == marker.cat || price <= marker.price) || ( price <= marker.price && cat == marker.cat){
     var content = 'MY DATA CONTENT USING MARKER';
     $('.result').append(content);  
   }
});

My if condition is not working.

Can any one help?

2
  • 1
    It's me or there is some missing parentheses ? Commented Oct 9, 2014 at 7:44
  • what is cat here in javascript Commented Oct 9, 2014 at 7:44

2 Answers 2

2

Your if condiition's parenthesis are all messed up, try this:

if ((cat == marker.cat || price <= marker.price) || ( price <= marker.price && cat == marker.cat))
Sign up to request clarification or add additional context in comments.

Comments

0
$(json).each(function(i,marker){
    if (cat == marker.cat || price <= marker.price) || ( price <= marker.price && cat == marker.cat){
     var content = 'MY DATA CONTENT USING MARKER';
     $('.result').append(content);  
   }

In this code the value of cat is not defined, you need to either change it to

this.cat or json[i].cat

to access the json values.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.