Flex - 检查选项卡下字段的更改
我正在开发一个带有 4 个选项卡的 Flex 应用程序。 当用户切换选项卡时,我想将前一个选项卡重置为其初始状态。 另外我需要提醒用户,如果他没有保存所做的更改(如果有的话),将会丢失。
我计划在模型中设置一个变量,并在选项卡下的字段中发生任何更改时设置/重置它。 但我该如何监控呢? 有没有可用的监听器?
另外,如何检查和重置上一个选项卡的状态? 该选项卡下的内容仅来自组件。
[编辑] 我的问题是:
- 如何检查用户是否在当前选项卡中进行了任何编辑? 有些字段也是动态生成的。
- 我在 TabNavigator 的 onchange 事件中调用一个函数,并询问用户是否确实要切换选项卡。我希望仅当用户在弹出的警报框中单击“是”时,另一个选项卡才能加载其内容。 但现在会弹出确认框,内容会加载到另一个选项卡中,如果用户单击“否”,则会返回到另一个选项卡。 在用户按下“是”之前,如何阻止加载其他选项卡内容的操作?
请提供您的宝贵意见。
I'm developing a flex application with 4 tabs. When the user switches a tab I want to reset the previous tab to its initial state. Also I need to alert the user, if he hasn't saved the changes he made if any, will be lost.
I'm planning to set a variable in the Model, and set/reset it if any change happens in a field under a tab. But how do I monitor this? Is there any listener available for this?
Also how do I check and reset the state of the previous tab? The contents that come under the tab is from components only.
[EDIT]
My questions are:
- How do I check if the user has made any edits in the current tab? Some fields are generated dynamically too.
- I'm calling a function in the onchange event of TabNavigator and asks the user if he really want to switch the tab.I want the other tab to load its contents only if the user clicks Yes to the Alert box I'm popping up. But now the confirmation box pops up, and the contents are loaded into the other tab and if the user clicks No it goes back to the other tab. How do I prevent the action of loading the contents of the other tab at all till the user presses Yes?
Please provide your valuable inputs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对问题1的回答如下;
使用布尔变量来跟踪用户是否编辑了数据。 当用户选择选项卡时,将此变量设置为 false。 监听选项卡内所有字段的更改事件。 将所有字段的更改事件处理程序设置为将布尔值设置为 true 的方法。 对于动态字段,添加与其他字段相同的更改事件处理程序。 创建每个动态字段后立即执行此操作。 请参阅下面的代码;
Answer to question 1 is as follows;
Use a Boolean variable to track if a user has edited data. When the user selects a tab set this variable to false. Listen for the change event on all fields within the tab. Set the change event handler for all fields to be a method which sets the Boolean to true. For the dynamic fields, add the same change event handler that the other fields have. Do this as soon as you create each dynamic field. See the code below;
我还没有添加评论的声誉,但可以回答您的问题:
“是否可以添加一个全局 onchange/onkeypress 方法来挂钩整个应用程序并设置布尔值?否则我将不得不在多个位置进行编辑以添加 onchange 事件 – Basani”
是的,让每个需要发出“发生变化”信号的位置调度一个事件。 然后让指挥部监视该事件的调度。 该命令可以执行您需要的所有处理,包括在模型中设置 userDataChanged 布尔值。
听起来您正在根据您标记问题的方式使用 Cairngorm,所以这应该很容易支持。
I don't have the reputation to add comments yet, but to answer your question:
"Is it possible to add a global onchange/onkeypress method that hooks to the complete application and sets the boolean? Otherwise I'll have to edit at multiple places to add the onchange event. – Basani"
Yes, have each place that needs to signal that "something changed" dispatch an Event. Then have a Command watching for dispatches of that event. That Command can do all the processing you need, including setting the userDataChanged boolean in the model.
It sounds like you're using Cairngorm based on how you tagged the question, so this should be easily supported.
对于 1),您可以在每次用户编辑字段时调度一个事件。 该事件可以通过命令来处理,该命令将使用有关更新内容的正确信息来更新模型中的某些属性。 然后,您认为关心的任何人都可以绑定到这些属性。
对于 2),在 onChange() 处理程序中调用 event.preventDefault()。 然后,仅当用户单击“是”时,您才能以编程方式选择下一个选项卡。
For 1) you could dispatch an Event every time a user edits a field. The event can be handled by a command which will update some properties in your model with the right info about what got updated. Then whoever cares in your view can bind to those properties.
For 2) in the onChange() handler call event.preventDefault(). Then you can programatically select the next tab only if the user clicks Yes.