如何在为 dijit/form/TextBox 正确设置值时避免触发事件 'change'?
How to avoid firing event 'change' when setting a value properly for a dijit/form/TextBox?
我需要为小部件 dijit/form/TextBox
更改 属性 value
,但我注意到每当我使用 widget.set('value','some value');
时事件 change
都会被触发在小部件上。
我需要在不触发 change
事件的情况下以编程方式正确更改它。知道如何实现吗?
https://jsfiddle.net/s5620bwd/6/
require(['dijit/form/TextBox', 'dojo/on'], function(TextBox, on) {
var textBox = new TextBox({
intermediateChanges: true
}, 'button');
on(textBox, 'change', function(value) {
this.set('value', value);
console.log(this.get('value')); // widget updated
});
// change value programmatically
textBox.set('value', 'value change programmatically');
});
TextBox 小部件有一个名为 textbox
的 属性,它对应于小部件中包含的输入元素。如果您在元素上设置值,它将不会触发任何事件侦听器。
require(['dijit/form/TextBox', 'dojo/on'], function(TextBox, on) {
var textBox = new TextBox({
intermediateChanges: true
}, 'button');
textBox.on('change', function(value) {
// this event handler will not fire
this.set('value', value);
console.log(this.get('value'));
});
textBox.textbox.value = 'my new value';
});
此外,要将事件处理程序附加到小部件,您应该使用小部件自己的 on
方法来附加处理程序。
我需要为小部件 dijit/form/TextBox
更改 属性 value
,但我注意到每当我使用 widget.set('value','some value');
时事件 change
都会被触发在小部件上。
我需要在不触发 change
事件的情况下以编程方式正确更改它。知道如何实现吗?
https://jsfiddle.net/s5620bwd/6/
require(['dijit/form/TextBox', 'dojo/on'], function(TextBox, on) {
var textBox = new TextBox({
intermediateChanges: true
}, 'button');
on(textBox, 'change', function(value) {
this.set('value', value);
console.log(this.get('value')); // widget updated
});
// change value programmatically
textBox.set('value', 'value change programmatically');
});
TextBox 小部件有一个名为 textbox
的 属性,它对应于小部件中包含的输入元素。如果您在元素上设置值,它将不会触发任何事件侦听器。
require(['dijit/form/TextBox', 'dojo/on'], function(TextBox, on) {
var textBox = new TextBox({
intermediateChanges: true
}, 'button');
textBox.on('change', function(value) {
// this event handler will not fire
this.set('value', value);
console.log(this.get('value'));
});
textBox.textbox.value = 'my new value';
});
此外,要将事件处理程序附加到小部件,您应该使用小部件自己的 on
方法来附加处理程序。