BindingUtils.bindProperty 中的奇怪行为:非确定性

发布于 2024-11-14 12:16:26 字数 458 浏览 1 评论 0原文

我有点生气了。

我在使用 BindingUtils.bindSetterbindProperty 时遇到了奇怪的问题。我认为,如果我使用 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:

enter image description here

What am I missing?

Thanks in advance,
Nuno

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫南 2024-11-21 12:16:26

您定义的绑定是单向的。当设置 drhHold.pending 时,this.pendingHold 将被设置。这并不是相反的情况。

换句话说,如果您有以下代码,则可能会发生您所描述的情况:

this.drhHold.pending = false;
this.pendingHold = true;

如果您希望双向,那么您需要设置另一个方向:

BindingUtils.bindProperty(this, "pendingHold", drhHold, "pending", false, true);
BindingUtils.bindProperty(drhHold, "pending", this, "pendingHold", false, true);

当然,所有这一切都假设这两个属性都是[可绑定]

The binding you defined is one-way. When drhHold.pending is set, then this.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:

this.drhHold.pending = false;
this.pendingHold = true;

If you want this to go both ways, then you need to set up the other direction:

BindingUtils.bindProperty(this, "pendingHold", drhHold, "pending", false, true);
BindingUtils.bindProperty(drhHold, "pending", this, "pendingHold", false, true);

All of this, of course, assumes that both of these properties are [Bindable].

我也只是我 2024-11-21 12:16:26

在这种情况下不需要绑定:

public class Class1
{
   private var _class2:Class2 = new Class2();

   [Bindable]
   public function get pending():Boolean
   {
      return this._class2.pending;
   }

   public function set pending(value:Boolean):void
   {
      this._class2.pending = value;
   }
}

只要 Class2.pending 也是可绑定的,这将使 Class1.pending 绑定到 Class2.pending。

Binding isn't needed in this case:

public class Class1
{
   private var _class2:Class2 = new Class2();

   [Bindable]
   public function get pending():Boolean
   {
      return this._class2.pending;
   }

   public function set pending(value:Boolean):void
   {
      this._class2.pending = value;
   }
}

As long as Class2.pending is bindable as well, this will make it so that Class1.pending is binded to Class2.pending.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文