Backbone.js populating a collection with fetch and data -- how to pass duplicate keys? Backbone.js populating a collection with fetch and data -- how to pass duplicate keys? flask flask

Backbone.js populating a collection with fetch and data -- how to pass duplicate keys?


You can pass a querystring with duplicate keys using an Array as a value.

this.fetch({ data: $.param({ filter1: ['value1','value2']}) });

Or, you can always set the URL like this with querystring params.

var MyModel = Backbone.Model.extend({  "url": function() {      return '/' + encodeURI('?filter1=' + val1 + '&filter1=' + val2);  }});

If you have to change params all the time, you can do something like and work with it directly:

this.model.destroy({    url: '/' + encodeURI('?filter1=' + val1 + '&filter1=' + val2)              });

If you have multiple concrete params (meaning the values changes but the key are static) that changes per fetch (ie: search), you can check out a paging implementation on Gist that might be useful for your situation whatever it may be.

Hope this helps.


Thanks for everyone's input.

Apparently the data you pass does not have to be an object -- I found that the easiest way in my case was to pass a string ('filter1=val1&filter2=val2') to fetch() and that worked perfectly.