javascript - using variable to change Parse.com query -


i using following parse.com javascript query , need switch type of query based on variable.

  function searchparseexercises (queryparam, activefilters, searchparam) {           var exercise = [];           var tagsearch = parse.object.extend("exercises");           var query = new parse.query(tagsearch);       query.containsall("tags", activefilters);        query.limit(20);       query.find({         success: function(results) {           var exercisedata = {};           (var = 0; < results.length; i++) {             var object = results[i];             var exercisedata = {             exercisename : object.get('exercisename'),             exercisedescription : object.get('exercisedescription'),             images : object.get('images'),           }          exercise.push(exercisedata);         }          $scope.allexercises = exercise;         },         error: function(error) {           $ionicpopup.alert({             title: "error: " + error.code + " " + error.message             });         }       }); } 

to clarify requirement have both text search , filter search in template. if there text search should perform:

query.contains("exercisename", searchparam); 

if there activefilters should perform this:

query.containsall("tags", activefilters); 

however if both variables present (searchparam , activefilters) should perform compound query.

i have no idea how can wire cleanly.

what understood question:

if (activefilters && searchparam) {    parse.query.or(activefilters, searchparam).find({      success: function(results) {          // results contains list of players either have won lot of games or won few games.      },      error: function(error) {          // there error.      } } else if (activefilters) {     query.containsall("tags", activefilters); } else if (searchparam) {     query.contains("exercisename", searchparam);    } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -