Automatically change model fields on view change in backbone.js

I have a popup with a lot of options that can be edited - this is the Backbone view. I have a model, which is a simple POCO, that stores these parameters. It is very difficult to write each view event handler to update the corresponding model values.

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

Let's say I have a textbox Name

that matches model.name

. I need to update model.name

automatically when I enter a new name in the textbox. Is it possible?

I know this way will not be mvc, but mvvm, and it might be better to use knockout.js here, but I already have the code for the trunk, so hopefully some workaround can be found.

+3


source to share


2 answers


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



This plugin will allow you to automatically update the model if the corresponding view fields have changes.

+1


source


From within the view, you just update it with this. this.model = SomeOtherModel;



0


source







All Articles