I am using a test .json file and can console.log the url fine in the success, but I am trying to now append parameters to the url and they are being ignored.
This is what the view looks like, works fine and success message appears with a test json file:
busImportSearch: function() {
importSelect.fetch({
data: {
importPhone: '5555555555',
busImportName: 'test business',
busImportCID: '12345',
busImportBID: '1234567890'
},
success: function(results) {
// url console.log's fine just no params
}
});
}
This is what I have in the collection:
var importSelect = Backbone.Collection.extend({
model: importModel,
url:'somepath/test.json',
sync: function(method, model, options) {
options.timeout = 10000;
options.dataType = "json";
return Backbone.sync(method, model, options);
},
parse: function(response) {
console.log(this.url);
if (typeof response.data !== 'undefined') {
this.result = response.data.list;
}
return this.result;
},
});
return new importSelect;
});
Edit
I think this is working but I think there is a better way to do this:
url: function() {
var busimportPhone = $("#busImportPhone").val();
var busImportName = $("#busImportName").val();
var busImportCID = $("#busImportCID").val();
var busImportBID = $("#busImportBID").val();
var updateUrl = 'test.json' + '?importPhone=' + busimportPhone + '&importName=' + busImportName + '&importCID=' + busImportCID + '&importBID' + busImportBID; return updateUrl;
},
This is not a whole lot better, but you could store the list of properties on the collection some where and create the url from there. Eg.
And construct your url using a function something like (code not tested)
and use function to create Url
hope that helps.