改变“启用” Flex 运行时按钮的值

发布于 2024-09-05 21:46:22 字数 419 浏览 6 评论 0原文

如果数据网格为空,我想禁用一个按钮,并且应该在至少有 1 个条目时启用该按钮。网格中的条目是在运行时创建的。我尝试了这个 这是按钮:

<mx:Button id="update" label="Update Contact" enabled="{isButtonEnabled()}"/>

函数定义为其中 dg_contact 是数据网格:

public function isButtonEnabled():Boolean
{
     if(dg_contact.selectedIndex==-1)
    {
        return false;
    }
    else
    {
        return true;
    }
}

我哪里出错了?

i want to make a button disabled if a datagrid is empty and it should be enabled when there is atleast 1 entry.the entries in the grid are made at runtime.I tried this
this is the button:

<mx:Button id="update" label="Update Contact" enabled="{isButtonEnabled()}"/>

and the function is defined as where dg_contact is the datagrid:

public function isButtonEnabled():Boolean
{
     if(dg_contact.selectedIndex==-1)
    {
        return false;
    }
    else
    {
        return true;
    }
}

where am i going wrong?

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

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

发布评论

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

评论(1

别把无礼当个性 2024-09-12 21:46:22

您的代码不起作用,因为当 selectedIndex 更改时,不会调用 isButtonEnabled()。您可以使用 BindingUtils 来做到这一点,但这可以在没有 BindingUtils 的情况下完成。

DataGrid 可以拥有项目,但也有其 selectedIndex 等于-1。如果您不关心某个项目是否被选中,请将其绑定到 DataGriddataProvider 的长度,

<mx:Button id="update" label="Update Contact" 
               enabled="{dg_contact.dataProvider.length != 0}"/>

如果您希望仅在某些内容被选中时启用按钮选择,将其绑定到 selectedIndex

<mx:Button id="update" label="Update Contact" 
               enabled="{dg_contact.selectedIndex != -1}"/>

Your code doesn't work because isButtonEnabled() doesn't get called when selectedIndex changes. You can use BindingUtils to do that, but this can be done without BindingUtils

DataGrid can have items and yet have its selectedIndex equal to -1. If you're not bothered about if an item is selected or not, bind it to the length of DataGrid's dataProvider

<mx:Button id="update" label="Update Contact" 
               enabled="{dg_contact.dataProvider.length != 0}"/>

If you want button to be enabled only when something is selected, bind it to selectedIndex

<mx:Button id="update" label="Update Contact" 
               enabled="{dg_contact.selectedIndex != -1}"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文