改变“启用” Flex 运行时按钮的值
如果数据网格为空,我想禁用一个按钮,并且应该在至少有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码不起作用,因为当
selectedIndex
更改时,不会调用isButtonEnabled()
。您可以使用BindingUtils
来做到这一点,但这可以在没有BindingUtils
的情况下完成。DataGrid
可以拥有项目,但也有其selectedIndex 等于-1。如果您不关心某个项目是否被选中,请将其绑定到
DataGrid
的dataProvider
的长度,如果您希望仅在某些内容被选中时启用按钮选择,将其绑定到
selectedIndex
Your code doesn't work because
isButtonEnabled()
doesn't get called whenselectedIndex
changes. You can useBindingUtils
to do that, but this can be done withoutBindingUtils
DataGrid
can have items and yet have itsselectedIndex
equal to -1. If you're not bothered about if an item is selected or not, bind it to the length ofDataGrid
'sdataProvider
If you want button to be enabled only when something is selected, bind it to
selectedIndex