BindingUtils.bindProperty 中的奇怪行为:非确定性
我有点生气了。
我在使用 BindingUtils.bindSetter
和 bindProperty
时遇到了奇怪的问题。我认为,如果我使用 BindingUtils.bindProperty 绑定两个变量,我可以确保它们始终是同步的。但事实并非如此。
我在creationCompleteHandler中有这段代码:
BindingUtils.bindProperty(this, "pendingHold", drhHold, "pending", false, true);
但是当我调试时,应该在某个时刻绑定在一起的两个变量具有不同的值:
我缺少什么?
提前致谢, 努诺
I'm going slightly mad.
I'm having weird problems with BindingUtils.bindSetter
and bindProperty
. I thought that, if I'd bind two variables with BindingUtils.bindProperty
I could be sure they would always be synchronized. But it's not so.
I have this code in a creationCompleteHandler:
BindingUtils.bindProperty(this, "pendingHold", drhHold, "pending", false, true);
But when I debug, the two variables that should be bound together at some point have different values:
What am I missing?
Thanks in advance,
Nuno
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您定义的绑定是单向的。当设置
drhHold.pending
时,this.pendingHold
将被设置。这并不是相反的情况。换句话说,如果您有以下代码,则可能会发生您所描述的情况:
如果您希望双向,那么您需要设置另一个方向:
当然,所有这一切都假设这两个属性都是
[可绑定]
。The binding you defined is one-way. When
drhHold.pending
is set, thenthis.pendingHold
will get set. This does not go the other way around.In other words, what you are describing can happen if you have the following code:
If you want this to go both ways, then you need to set up the other direction:
All of this, of course, assumes that both of these properties are
[Bindable]
.在这种情况下不需要绑定:
只要 Class2.pending 也是可绑定的,这将使 Class1.pending 绑定到 Class2.pending。
Binding isn't needed in this case:
As long as Class2.pending is bindable as well, this will make it so that Class1.pending is binded to Class2.pending.