Jackie Chan
Jackie Chan

Reputation: 2662

backbone sync passes wrong parameters

It's a pretty simple trick that I thought should work fine however it doesn't. So I have multiple checkboxes on the page. And whenever they are changed I would like to record any change to the database. So in the view event 'click' on checkbox I have similar to this:

var filter_name = $(e.target).attr("name");
var filter_value = $( "input:checkbox[name=" + filter_name + "]:checked" ).map(function () {
        return this.value;
}).get();


console.log("filter_name: " + filter_name); #=> my_method_name

CarInsuranceApp.aciq.set({filter_name: filter_value});
CarInsuranceApp.aciq.save();

And here the results that I receive as a JSON:

"filter_name"=>"extra"

So my question would be how to dynamically pass model attribute name on the set?

Upvotes: 0

Views: 71

Answers (2)

Sathya
Sathya

Reputation: 5308

use like this.

CarInsuranceApp.aciq.set(filter_name, filter_value);

Upvotes: 2

Jackie Chan
Jackie Chan

Reputation: 2662

Here is a possible one line JavaScript`ish solution:

CarInsuranceApp.aciq.attributes[filter_name] = filter_name;

Upvotes: -1

Related Questions