本文介绍了Flex 组合框 preChange 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我需要在更改组合框值之前向用户弹出警报.此功能允许用户在未保存修改的情况下保持当前状态.这意味着用户将能够取消更改.

I have a project in which i need to pop up an alert to the user before a combobox value is changed.This feature is to allow the user to stay in current state if modifications were not saved. Meaning that the user will be able to cancel the change.

我已经对 ComboBox 进行了子类化,并尝试挂钩 ComboBox.dropdown 的 ITEM_CLICK,但在更改值后会触发此事件.另外,我试过 MOUSE_CLICK 和 MOUSE_DOWN 但没有成功.

I have sub classed ComboBox and tried to hook on ITEM_CLICK of ComboBox.dropdown but this event is triggered after the value is changed. Also, I've tried MOUSE_CLICK ans MOUSE_DOWN but without success.

在我的代码中,我向我的 CustomComboBox 添加了一个preChange"事件.此事件应在进行更改之前触发.此外,我还引入了一个名为 commitChange 的方法,该方法将被手动调用以实际提交更改.

In my code, I have added a "preChange" event to my CustomComboBox. This event should be triggered before a change is made. Also, I've introduced a method called commitChange that will be called manually to actually commit the change.

我怎样才能达到预期的效果?

How can I achieve the desired result?

推荐答案

最简单的方法是在 ComboBox 的 Event.CHANGE 中添加两个监听器,然后设置要触发的处理程序的优先级 在变化之前为负值.例如:

The easiest way to do it is to add two listeners to Event.CHANGE on the ComboBox, then set the priority of the handler you want to fire prior to the change as a negative value. For example:

myComboBox.addEventListener(Event.CHANGE, preChange, false, -100);
myComboBox.addEventListener(Event.CHANGE, postChange, false, 100);

事件分发的顺序:

  1. preChange(event:Event)
  2. 继承的更改事件(自动具有默认优先级为 0)
  3. postChange(event:Event)

这篇关于Flex 组合框 preChange 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:36