Last active
August 4, 2016 01:18
-
-
Save tuanphpvn/9800f59b3ab10fc96900 to your computer and use it in GitHub Desktop.
Change param in query #Javascript #Params
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
change_param_in_query_by_key_value = function(key, value, query) { | |
var arrParams = query.parseQuery(); | |
if(typeof arrParams[key] === "undefined") { | |
return query; | |
} | |
var _value = arrParams[key], _arr = _value.split('-'); | |
var position_occur_in_value_query = $j.inArray(value, _arr); | |
if(position_occur_in_value_query === -1) { | |
return query; | |
} | |
_arr.splice(position_occur_in_value_query, 1); // remove it | |
arrParams[key] = _arr.join('-'); | |
return Object.toQueryString(arrParams).gsub("%2B", "+"); | |
}; | |
change_param_in_query_by_key_value(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment