简体   繁体   English

不触发valueChange的自定义元素双向绑定更新

[英]Custom element two-way binding update without triggering valueChange

I have a situation here, the valueChanged gets called even if I change the bindable property value internally within custom element.我在这里遇到了一个情况,即使我在自定义元素内部更改了可绑定属性value也会调用valueChanged How do I send the updated value back to viewModel from custom element without triggering valueChanged for that bindable value.如何在不触发该可绑定值的valueChanged的情况下,将更新的值从自定义元素发送回 viewModel。

is there a way to supress this?有没有办法抑制这种情况? or I have to use internal tracking if this is called from internal code or coming from view?或者如果这是从内部代码调用或来自视图,我必须使用内部跟踪?

There is no way to prevent a bindable property's change handler method from being called based on whether the custom element's own code is assigning the property or whether it's being assigned by external code or in response to user input.没有办法阻止可绑定属性的更改处理程序方法根据自定义元素自己的代码是分配属性还是由外部代码分配或响应用户输入而被调用。 You will have to roll your own internal tracking mechanism.您将不得不推出自己的内部跟踪机制。

As Jeremy said, there's no way to prevent a bindable property's change handler from being called.正如 Jeremy 所说,没有办法阻止可绑定属性的更改处理程序被调用。 However, you could attach or trigger your code only with the form input using the change.delegate or keyup.delegate properties.但是,您只能通过使用change.delegatekeyup.delegate属性的表单输入来附加或触发您的代码。 That would allow you to isolate your event code from the changes resulting from binding properties.这将允许您将事件代码与绑定属性导致的更改隔离开来。

Here's a GistRun to demonstrate this:这是一个 GistRun 来演示这一点:

https://gist.run/?id=11cd1e90dd912f07a60afaedb9c2613b https://gist.run/?id=11cd1e90dd912f07a60afaedb9c2613b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM