我想将的启用的基于一个函数,有一个或多个参数的返回值的按钮属性。我怎样才能做到这一点?
私有函数isUserAllowed(用户名:布尔):布尔{
如果(用户名=='汤姆')
返回true;
如果(用户名=='法案')
返回false;
}
< MX:按钮标签=创建采购订单ID =createPOButton
启用=<我想打电话给isUserAllowed('法案')或isUserAllowed('汤姆')这里>中
点击=createPOButton_Click()/>
解决方案
< MX:按钮
启用={this.myFunction(this.myVariable)}
>
或内嵌:
< MX:按钮
启用={(功能(ARG:对象):布尔{...})(this.myVariable)}
>
I want to set the enabled property on a button based on the return value of a function that has one or more parameters. How can I do this?
private function isUserAllowed (userName:Boolean):Boolean {
if (userName == 'Tom')
return true;
if (userName == 'Bill')
return false;
}
<mx:Button label="Create PO" id="createPOButton"
enabled="<I want to call isUserAllowed ('Bill') or isUserAllowed ('Tom') here>"
click="createPOButton_Click()" />
解决方案
<mx:Button
enabled = "{this.myFunction(this.myVariable)}"
>
or inline:
<mx:Button
enabled = "{(function(arg:Object):Boolean{ ... })(this.myVariable)}"
>