change model fields automatically when view changed in backbone.js

Go To StackoverFlow.com

3

I have a pop up with plenty of options which can be edited - this is a Backbone View. I have a model which is simple POCO that stores those options. It's quite hard to write each view event handler to update the model's corresponding values.

How do I update the model automatically when its view fields change?

Assume I have textbox Name which corresponds to model.name. I need to update model.name automatically when I enter a new name in the textbox. Is it possible?

I know that this way will not be mvc, but mvvm, and maybe it's better to use knockout.js here, but I already have some code for backbone, so hope it is possible to find some workaround.

2012-04-05 16:59
by Ph0en1x


1

You can manage your form to model updates with Backbone Forms.

This plugin will allow you to update the model automatically when related view fields have changes.

2012-04-05 18:09
by Marty Cortez
ok, but it's not possible without additional plugin - Ph0en1x 2012-04-05 18:32


0

From inside the view, you'd simply redeclare it with this. this.model = SomeOtherModel;

2012-04-05 17:02
by AlienWebguy
Ads