[英]paper-input change event not fired when setting value
I add an eventListener
for the change-event
to a bunch of paper-inputs
. 我将
change-event
的eventListener
添加到一堆paper-inputs
。
Now when I change manually (by click or typing) the value
of the paper-input
the event
fires as expected, but when I set the value
through code, the zero is visible inside the input
but the event
doesn't fire. 现在,当我手动更改(通过单击或键入)
paper-input
的value
,该event
将按预期触发,但是当我通过代码设置该value
, input
的零可见,但该event
不会触发。
Code: 码:
for(var i = 0; i<this.children.length; i++){
this.children[i].children[0].set('value',0);
this.children[i].children[0].addEventListener('change', function(e){
e.detail = {"name" : e.srcElement.name,
"value": e.srcElement.value
}
pushToChecked(e);
})
}
I call the following function to reset all my inputs when needed: 我在需要时调用以下函数来重置所有输入:
_setToZero : function(){
for(var i = 0; i<this.children.length; i++){
this.children[i].children[0].set('value',0);//should fire change-event
}
}
this.children[i]
looks like this: this.children[i]
看起来像这样:
<div class="obj-input">
<paper-input class="paper-number" type="number" min="0" name="test">
</paper-input>
</div>
Any Ideas? 有任何想法吗? Help would be greatly appreciated.
帮助将不胜感激。
Just ask me if you need to see more code. 请问我是否需要查看更多代码。
Typical <input>
does not fire change
event when value
is changed from code, so I believe <paper-element>
is expressing the platform behavior. 当
value
从代码change
时,典型的<input>
不会触发change
事件,因此我相信<paper-element>
表示平台行为。
However, <paper-element>
will fire (non-bubbling) value-changed
event that you can use instead. 但是,
<paper-element>
将触发(不冒泡) value-changed
事件,您可以使用它来代替。
<base href="http://polygit.org/components/"> <script src="webcomponentsjs/webcomponents-lite.min.js"></script> <link rel="import" href="paper-input/paper-input.html"> <style> body { font-family: sans-serif; } </style> <x-example></x-example> <dom-module id="x-example"> <style> :host { display: block; } </style> <template> <paper-input placeholder="input" on-change="change" on-value-changed="valueChanged" value="{{value}}"></paper-input> <button on-tap="changeValue">Change Value</button> </template> <script> // only need this when in the main document and on non-Chrome addEventListener('WebComponentsReady', function() { Polymer({ is: 'x-example', changeValue: function() { this.value = Math.floor(Math.random() * 1000); }, change: function() { console.log('got _change_ event'); }, valueChanged: function() { console.log('got _value-changed_ event'); } }); }); </script> </dom-module>
Note: check the console to see the events fire if you run the snippet. 注意:如果运行代码段,请检查控制台以查看事件触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.