Backbone JS - Set model attribute node object with value

Go To StackoverFlow.com

0

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

I have one model for my entire page called FD.page. I have an attribute of that model called filters, thus FD.page.get("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 FD.page.set("filters.location", "close");

Any help will be much appreciated. Thanks!

2012-04-04 02:23
by createbang


1

Make filters a backbone model

FD.page.get('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


1

try FD.page.get('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
Ads