淘汰赛:自定义绑定处理程序上的valueAccessor vs viewModel? [英] Knockout: valueAccessor vs viewModel on custom binding handlers?

查看:59
本文介绍了淘汰赛:自定义绑定处理程序上的valueAccessor vs viewModel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过绑定属性(通过valueAccessor)访问视图模型的值与从传递给处理程序的init和update的viewModel参数获取它们之间有什么区别?我一直以为答案是链接到valueAccessor的那些模型属性会自动设置绑定(这将触发可观察对象的任何更新),但是我不确定.

What's the difference between getting access to a view model's values through the binding properties (via valueAccessor) and getting them from the viewModel argument passed to the handler's init and update? I have always assumed the answer is that those model properties linked to valueAccessor automatically set up bindings (which would fire an update on any change to observables) but I'm not sure about that.

推荐答案

valueAccessor参数使您可以访问传递给绑定的内容,而viewModel参数使您可以访问位于目录的整个数据对象.范围.

The valueAccessor argument gives you access to specifically what was passed into the binding, while the viewModel argument gives you access to the entire data object at the scope.

所以,如果有人说text: firstName

valueAccessor()将为您提供firstName可观察/属性,而viewModel将为您提供对包含firstName的对象的访问权限.

valueAccessor() would give you the firstName observable/property and viewModel would give you access to the object that contains firstName.

这篇关于淘汰赛:自定义绑定处理程序上的valueAccessor vs viewModel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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