Backbone JS - Set model attribute node object with value

Go To


So the title is a little confusing, I think, but here's the issue:

I have one model for my entire page called I have an attribute of that model called filters, thus"filters") returns an object with multiple attributes itself, date, location, etc.

I would like to be able to set values to the attributes of the filters attribute, and I can't seem to figure out how to specify that node.

So something like"filters.location", "close");

Any help will be much appreciated. Thanks!

2012-04-04 02:23
by createbang


Make filters a backbone model'filters').set('location', 'close');

Will fire change event.

2012-04-04 02:30
by tkone
That's it. Sweet. Not sure why I didn't think of that. Thanks - createbang 2012-04-04 03:01


try'filters')['location'] = 'close';

This won't fire a change event on the model though. If you want to fire the change event, then you'll have to fire it manually after you set it.

2012-04-04 02:25
by Paul