获取任何元素的变化
我有一个带有一些组件(textInput、textArea、checkBox)的屏幕。我想检查一下组件是否有任何变化。例如,如果已输入文本或已单击复选框。
有没有直接的方法来做到这一点,而不是检查每个组件的值,然后为此设置一个布尔值?
谢谢
I have a screen with a few components (textInput, textArea, checkBox). I want to check if there has been any changes to the components. Foe example if text has been entered or checkbox has been clicked.
Is there a direct way to do this instead of checking value of each component and then setting a Boolean for this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您列出的三个 Spark 组件(TextInput、TextArea、CheckBox)都侦听更改事件。只需调用一个函数即可在每个组件上发生更改事件时收到通知,如下所示:
The three Spark components you listed (TextInput, TextArea, CheckBox) all listen for a change event. Simply call a function to be notified when change events occur on each component, like so:
您可以创建一些包含数据并跟踪更改的类。并使用两种方式绑定将控件与该数据对象字段绑定。
数据对象的基类如下所示:
此实现依赖于以下类型的命名约定:
因此私有字段的命名应与访问器相同,但以下划线开头。
如果您用多个字段(字符串、布尔值等)填充数据类,您可以按以下方式使用它:
此代码只是一个草稿,但我希望您明白:)
You can create some class which contains data and tracks changes. And bind controls with this data object fields using two way binding.
The base class for you data object can look like the following:
This implementation relies on naming convention of the following kind:
So private field should be named the same as accessor but starting with underscore.
If you fill your data class with several fields (strings, booleans etc) you can use it the following way:
This code is just a draft but I hope you get the idea :)
您可以在每个组件上注册一个事件侦听器以自动侦听更改。
如果您试图弄清楚从特定时间(或最后检查的实例)是否发生了更改,唯一的方法(我知道)是存储先前的输入(输入的哈希值)并将其与当前输入(输入的哈希值)进行比较当前输入)。
You can register an event listener on each of the components to automatically listen for changes.
If you are trying to figure out if a change has occurred from a specific time (or last checked instance) the only way (I know) would be storing the previous input (hash of input) and comparing it to the current input (hash of the current input) .