admin管理员组文章数量:1431419
I've been trying to create an event to be triggered given certain conditional (more general case), but I have not found a way, at least not in the official documentation of Polymer for handling events
.5/articles/munication.html
The custom element listen to another event, so he expects a condition is met to throw the internal event.
This is a little descriptive example:
Index.html
...
<my-element></my-element>
...
<script>
var ele = document.querySelector("my-element");
ele.addEventListener("myCustomEvent",
function(){
// some action
...
})
</script>
This code describes who will be listening to the event (myCustomEvent
) and an action is detonated.
The other hand es the implementation of the custom element
<polymer-element name="my-element">
<template>
<other-custom-element id="foo"></other-custom-element>
</template>
<script>
Polymer("my-element", {
ready: function(){
var foo = this.$.foo;
foo.addEventListener("AnotherEvent" , function(){
...
if(condition){
...
// in this part I need to fire the event
// "myCustomEvent"
}
})
}
})
</script>
</polymer-element>
My problem is to fire the event when the condition is done, And listen that event outside (in index.html)
References
- .5/articles/munication.html
- .5/docs/polymer/polymer.html#fire
I've been trying to create an event to be triggered given certain conditional (more general case), but I have not found a way, at least not in the official documentation of Polymer for handling events
https://www.polymer-project/0.5/articles/munication.html
The custom element listen to another event, so he expects a condition is met to throw the internal event.
This is a little descriptive example:
Index.html
...
<my-element></my-element>
...
<script>
var ele = document.querySelector("my-element");
ele.addEventListener("myCustomEvent",
function(){
// some action
...
})
</script>
This code describes who will be listening to the event (myCustomEvent
) and an action is detonated.
The other hand es the implementation of the custom element
<polymer-element name="my-element">
<template>
<other-custom-element id="foo"></other-custom-element>
</template>
<script>
Polymer("my-element", {
ready: function(){
var foo = this.$.foo;
foo.addEventListener("AnotherEvent" , function(){
...
if(condition){
...
// in this part I need to fire the event
// "myCustomEvent"
}
})
}
})
</script>
</polymer-element>
My problem is to fire the event when the condition is done, And listen that event outside (in index.html)
References
- https://www.polymer-project/0.5/articles/munication.html
- https://www.polymer-project/0.5/docs/polymer/polymer.html#fire
1 Answer
Reset to default 7Try this. (Note: changed event names to be case-insensitive ['AnotherEvent' -> 'another-event'] because the HTML is happier this way):
<polymer-element name="my-element">
<template>
<other-custom-element on-another-event="{{doAnotherEvent}}"></other-custom-element>
</template>
<script>
Polymer("my-element", {
doAnotherEvent: function(){
if (condition){
// in this part I need to fire the event
// "my-custom-event"
this.fire('my-custom-event');
}
}
});
</script>
</polymer-element>
本文标签: javascriptCreate a custom event for a Polymer CustomElementStack Overflow
版权声明:本文标题:javascript - Create a custom event for a Polymer Custom-Element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745528825a2661965.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论