Flex ChangeWatcher 绑定到否定条件

发布于 2024-10-10 14:55:35 字数 988 浏览 2 评论 0原文

我在组件中有一个可绑定的 getter,它会在[隐藏]计时器运行时通知我。我还有一个上下文菜单,如果该计时器正在运行,则应禁用其中一个菜单项。是否可以创建一个 ChangeWatcher 来监视可绑定属性/getter 的否定条件并更改菜单项的enabled 属性?

以下是我尝试绑定在一起的基本方法:

A 类:

[Bindable]
public function get isPlaying():Boolean {
    return (_timer != null) ? _timer.running : false;
}

B 类:

private var _playingWatcher:ChangeWatcher;
public function createContextMenu():void {
    //...blah blah, creating context menu
    var newItem:ContextMenuItem = new ContextMenuItem();
    _playingWatcher = BindingUtils.bindProperty(newItem, "enabled", _classA, "isPlaying");
}

在上面的代码中,我有相反的情况:当 isPlaying() 为 true 时,菜单项被启用;当 isPlaying() 为 true 时,菜单项被启用;当 isPlaying() 为 true 时,菜单项被启用;我希望它仅在条件为假时启用。

我可以创建第二个 getter(还有其他依赖于当前 getter 的绑定)来返回相反的条件,但这对我来说听起来很难看:

[Bindable]
public function get isNotPlaying():Boolean {
    return !isPlaying;
}

这可能吗,还是有另一种我完全缺少的方法?

I have a bindable getter in a component which informs me when a [hidden] timer is running. I also have a context menu which, if this timer is running, should disable one of the menu items. Is it possible to create a ChangeWatcher which watches for the negative condition of a bindable property/getter and changes the enabled property of the menu item?

Here are the basic methods I'm trying to bind together:

Class A:

[Bindable]
public function get isPlaying():Boolean {
    return (_timer != null) ? _timer.running : false;
}

Class B:

private var _playingWatcher:ChangeWatcher;
public function createContextMenu():void {
    //...blah blah, creating context menu
    var newItem:ContextMenuItem = new ContextMenuItem();
    _playingWatcher = BindingUtils.bindProperty(newItem, "enabled", _classA, "isPlaying");
}

In the code above, I have the inverse case: when isPlaying() is true, the menu item is enabled; I want it to only be enabled when the condition is false.

I could create a second getter (there are other bindings which rely on the current getter) to return the inverse condition, but that sounds ugly to me:

[Bindable]
public function get isNotPlaying():Boolean {
    return !isPlaying;
}

Is this possible, or is there another approach I'm completely missing?

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

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

发布评论

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

评论(2

-黛色若梦 2024-10-17 14:55:35

可以在绑定实用程序上使用绑定设置器,但您的方法似乎有效,否则绑定属性对其映射的属性类型是盲目的,因此它没有负条件参数。

Could use bind Setter on binding utils but your approach seems valid otherwise bind property is blind to the types of properties it's mapping so it has no negative condition parameter.

演多会厌 2024-10-17 14:55:35

我将扩展 ContextMenuItem 并在其上创建一个自定义属性,您可以使用它来设置底层 ContextMenuItem 的启用或禁用

I would extend ContextMenuItem and create a custom property on it that you can use to set the enabled or not of the underlying ContextMenuItem

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