0

I wanted to get URL parameters values using backbone route.

my URL will be like : http://www.mydomain.com/page?filters=1,2&unselectedFilters=1

I wanted to get values of filter and unselectedFilters?

please let me know how to get this kind of values in backbone route.

your help will be appreciated.

Thanks

Mike
  • 118
  • 1
  • 3
  • 11

1 Answers1

0

This doesn't really go with the spirit of backbone, but I assume since you are talking about Backbone routes you've read the documentation on them.

You can parse out these parameters from window.location.search.

// get rid of ? at the beginning.
var searchstr = window.location.search.slice(1, window.location.search.length);
// split each search parameter into array.
var parts = str.split('&');

var params = {};
// Loop through parts and parse key=value string into params.
for(var i= 0; i < parts.length; i++) {
  var pair = parts[i].split('=');
  params[pair[0]] = pair[1];
}

that will give you

Object {filters: "1,2", unselectedFilters: "1"}
zigzackattack
  • 343
  • 5
  • 11