A simple example using Backbone.js and Rivets.js

I am looking for a very simple example, for example, there is a two-way binding between the span text and the input element using Backbone.js and Rivets.js . It may be in the Rivets.js docs, but I can't find it. Any help please?

+4
source share
2 answers

Assuming you mean two-way binding (model-to-view and view to model) on the input element and one-way binding (model-to-view) on the span element, then the following view will do what you describe.

 <div id="user-view"> <span>{ user:name }</span> <input rv-value="user:name"> </div> 

Here is a fiddle that demonstrates action in action. It includes the Backbone adapter on the interface : and shows how to bind the model to the view (this is just a simpler example of what is already shown on the main page).

+6
source

I recommend you use: https://github.com/theironcook/Backbone.ModelBinder It can satisfy the two-way binding between the requirement of the whole view and model.

Here's what I do with a nested view binding example: http://files.cnblogs.com/justinw/Nested_Model_bi_Binding.zip

+3
source

All Articles