Simple Example using Backbone.js and Rivets.js

依然范特西╮ 提交于 2019-12-07 09:25:01

问题


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?


回答1:


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).




回答2:


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



来源:https://stackoverflow.com/questions/11719914/simple-example-using-backbone-js-and-rivets-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!