I am looking for a very simple example where e.g. there is a two way binding between span
text and an input
element using Backbone.js and Rivets.js. Perhaps there is one in the Rivets.js docs, but I can't find it. Any help please?
Asked
Active
Viewed 8,574 times
4

Michael Richards
- 1,791
- 14
- 19

Joe
- 1,841
- 4
- 27
- 43
2 Answers
6
Assuming that you mean a two-way binding (model-to-view and view-to-model) on an input element and a one-way binding (model-to-view) on a 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 things in action. It includes a Backbone adapter on the :
interface and shows how to bind a model to the view (this is just a more trivial example of what is already shown on the homepage).

Michael Richards
- 1,791
- 14
- 19
-
2how do you display collections of model objects with rivets currently? – rhodee Aug 07 '12 at 19:42
-
4@rhodee As of **0.3.2** there is a `data-each-[item]` binding to iterate over items in an array. – Michael Richards Aug 11 '12 at 02:14
-
@MichaelRichards can you explain why the click outside the input creates the change? how can we configure it to respond to something beside a click outside etc? – Alexander Mills Jul 23 '15 at 00:05
3
I recommend that you use: https://github.com/theironcook/Backbone.ModelBinder It can satisfy the two-way binding between the demand of all the view and model。
This is what I do nested view binding example: http://files.cnblogs.com/justinw/Nested_Model_bi_Binding.zip

Justin wong
- 638
- 6
- 15