From 5565a8cca61e95685b6b57f01b21762c1de35d98 Mon Sep 17 00:00:00 2001 From: Bart Vandendriessche Date: Sun, 12 Feb 2012 11:44:30 +0100 Subject: [PATCH] Allow query parameters to contain an array such as ?q=value1&q=value2 If the parameter key occurs only once, behaviour is unaltered, otherwise, the param object's value for the parameter key is turned into an array and subsequent values are pushed onto it. --- src/backbone_query_parser.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backbone_query_parser.js b/src/backbone_query_parser.js index 752e95f..c9c0bac 100644 --- a/src/backbone_query_parser.js +++ b/src/backbone_query_parser.js @@ -43,7 +43,13 @@ Backbone.Router.prototype._extractParameters = function (route, path) { path = path.substr(0, query); _.each(params, function(param) { param = param.split("="); - queryParams[param[0]] = param[1]; + if (_.isUndefined(queryParams[param[0]])) { + queryParams[param[0]] = param[1]; + } else if (_.isArray(queryParams[param[0]])) { + queryParams[param[0]].push(param[1]); + } else { + queryParams[param[0]] = [queryParams[param[0]], param[1]]; + } }); }