Flex:向 Alert closeHandler 发送参数

发布于 2024-10-18 11:30:19 字数 323 浏览 1 评论 0原文

是否可以向 closeHandler Alert 函数发送参数? 该函数获取的第一个参数是 CloseEvent,但是如何发送另一个参数呢?

<s:Button id="btnLoadLocalData" label="Load data"
          click="Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, loadLocalData(???parameters???), null, Alert.OK);"/>

谢谢你!

Is it possible to send parameters to a closeHandler Alert function?
The fisrt parameter the function gets is the CloseEvent, but how to send another one?

<s:Button id="btnLoadLocalData" label="Load data"
          click="Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, loadLocalData(???parameters???), null, Alert.OK);"/>

Thank you!

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

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

发布评论

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

评论(4

一袭白衣梦中忆 2024-10-25 11:30:19

一种方法可能是在警报创建范围内创建 closeHandler。

这是一个例子:

<s:Button id="btnLoadLocalData" label="Load data" click="btnLoadLocalData_clickHandler(event)"/>

function btnLoadLocalData_clickHandler(event:Event):void {
  var someVar:Object = someCalculation();
  var closeHandler:Function = function(closeEvent:CloseEvent):void {
    // someVar is available here
  };
  Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, closeHandler, null, Alert.OK);
}

An approach might be to create the closeHandler in the scope of the alert creation.

Here's an example:

<s:Button id="btnLoadLocalData" label="Load data" click="btnLoadLocalData_clickHandler(event)"/>

function btnLoadLocalData_clickHandler(event:Event):void {
  var someVar:Object = someCalculation();
  var closeHandler:Function = function(closeEvent:CloseEvent):void {
    // someVar is available here
  };
  Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, closeHandler, null, Alert.OK);
}
深海蓝天 2024-10-25 11:30:19

使用 Flex 的动态函数构造应该可以实现这一点。 此处提出了类似的问题

下面是一个示例:

参数和处理程序:

var parameters:String = "Some parameter I want to pass";

private function loadLocalData(e:Event, parameter:String):void
{
  // voila, here's your parameter
}

private function addArguments(method:Function, additionalArguments:Array):Function 
{
  return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
}

您的组件:

<s:Button id="btnLoadLocalData" label="Load data"
          click="Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, addArguments(loadLocalData, [parameters])), null, Alert.OK);"/>

This should be possible using Flex's dynamic function construction. A similar question was asked here.

Here's an example:

The parameters and handler:

var parameters:String = "Some parameter I want to pass";

private function loadLocalData(e:Event, parameter:String):void
{
  // voila, here's your parameter
}

private function addArguments(method:Function, additionalArguments:Array):Function 
{
  return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
}

Your component:

<s:Button id="btnLoadLocalData" label="Load data"
          click="Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, addArguments(loadLocalData, [parameters])), null, Alert.OK);"/>
゛时过境迁 2024-10-25 11:30:19

我处理此用例的典型方法是将数据添加到警报表单中。例如

var o:Object = new Object();
o["stuff"] = "quick brown fox";

var alert:Alert = Alert.show("Message", "Title", mx.controls.Alert.YES | mx.controls.Alert.NO, null, OnAlertResult);
alert.data = o;

然后在警报的关闭处理程序中

private function OnAlertResult(event:CloseEvent):void {
    trace(event.target.data);
}

My typical method of handling this use case is to add the data to the Alert form. For example

var o:Object = new Object();
o["stuff"] = "quick brown fox";

var alert:Alert = Alert.show("Message", "Title", mx.controls.Alert.YES | mx.controls.Alert.NO, null, OnAlertResult);
alert.data = o;

And then in the close handler for the Alert

private function OnAlertResult(event:CloseEvent):void {
    trace(event.target.data);
}
一个人练习一个人 2024-10-25 11:30:19

我通常使用匿名函数来包装带参数的函数调用:

Alert.show("Are you sure?", Alert.YES | Alert.CANCEL, null, function(event:CloseEvent):void{doSomething(event.detail, param1, param2);}, null, Alert.CANCEL)

I usually use an anonymous function to wrap a function call with parameters:

Alert.show("Are you sure?", Alert.YES | Alert.CANCEL, null, function(event:CloseEvent):void{doSomething(event.detail, param1, param2);}, null, Alert.CANCEL)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文