【问题标题】:changing "enabled" value of a button during runtime in flex在运行时在 flex 中更改按钮的“启用”值
【发布时间】:2010-06-15 12:21:16
【问题描述】:

如果数据网格为空,我想禁用一个按钮,并且应该在至少有 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;
    }
}

我哪里错了?

【问题讨论】:

    标签: apache-flex actionscript-3 actionscript button mxml


    【解决方案1】:

    您的代码不起作用,因为当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}"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 2023-04-05
      相关资源
      最近更新 更多