什么是双向绑定? [英] What is two way binding?

查看:171
本文介绍了什么是双向绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了大量的骨干没有做双向绑定,但我完全不理解这个概念。

I have read lots that Backbone doesn't do two way binding but I don't exactly understand this concept.

可能有人给我一个如何在MVC codeBase的双向绑定工作,以及它如何不与骨干?

Could somebody give me an example of how two way binding works in an MVC codebase and how it does not with Backbone?

推荐答案

双向绑定只是意味着:


  1. 当模型属性得到更新,所以没有UI。

  2. 当UI元素得到更新,将更改传播回模型。

骨干没有出炉,在实施#2(虽然你可以使用事件侦听器当然这样做)。其他框架像淘汰赛做线了双向绑定自动地的。

Backbone doesn't have a "baked-in" implementation of #2 (although you can certainly do it using event listeners). Other frameworks like Knockout do wire up two-way binding automagically.

在骨干网,你可以很容易地通过绑定视图的渲染的方法,以它的模型的改变事件达到#1。为了达到#2,你也需要改变监听器添加到输入元素,并在处理程序调用 model.set

In Backbone, you can easily achieve #1 by binding a view's "render" method to its model's "change" event. To achieve #2, you need to also add a change listener to the input element, and call model.set in the handler.

这里有一个小提琴与骨干双向绑定设置。

Here's a Fiddle with two-way binding set up in Backbone.

这篇关于什么是双向绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆