CanJS - 双向绑定

时间:2017-04-11 16:07:00

标签: canjs canjs-routing canjs-view

如何使用CanJS进行双向绑定?

Enter the Text : <input type="text" name="name" can-value="enteredText" />
Display the Text: {{enteredText}}

可以显示多种方法吗?使用ViewModel?

2 个答案:

答案 0 :(得分:1)

can-value是v2中的旧方法。在Canjs 4.0中,您可以像这样进行双向绑定:

Enter the Text : <input type="text" name="name" value:bind="enteredText" />
Display the Text: {{enteredText}}

请参阅:https://canjs.com/doc/can-stache-bindings.twoWay.html

这是一个演示语法的jsbin:

http://jsbin.com/vogavevico/edit?html,js,console,output

答案 1 :(得分:0)

请在此处查看(文件for v2for v3)。

至少如果您使用(现在推荐的)组件方法,您可以编写

<my-component {(some-prop)}="value"/><!-- v2 -->
<!-- syntax for v3 remains: {(prop)}="key" for two-way binding. -->

这是来自文档。

相关问题