Firebase 聚合物、纸按钮、在水龙头上发送参数都有效,但有时无效
我有几个按钮像贝娄,所有包装dom如果模板为贝娄Firebase 聚合物、纸按钮、在水龙头上发送参数都有效,但有时无效,firebase,polymer,web-component,Firebase,Polymer,Web Component,我有几个按钮像贝娄,所有包装dom如果模板为贝娄 <teplate is="dom-if" if="{{google}}"> <paper-button on-tap='_signIn' arg="#google">...<div></div><paper-button> </template> ..... <paper-button on-tap='_signIn' arg="#facebook">...
<teplate is="dom-if" if="{{google}}">
<paper-button on-tap='_signIn' arg="#google">...<div></div><paper-button>
</template>
.....
<paper-button on-tap='_signIn' arg="#facebook">...<div></div><paper-button>
<paper-button on-tap='_signIn' arg="#twitter">...<div></div><paper-button>
......
_signIn: function(e) {
console.log(e.target.getAttribute("arg"));
}
因此,我们需要稳定的结果。任何帮助或建议都将不胜感激 点击
div
内的paper按钮
将明显导致空值。。因为div没有arg
属性,调用e.target
返回div
。您应该显示没有任何子元素的纸张按钮,如:
<paper-button on-tap='_sigIn' arg="#google">Click me</paper-button>
因此,您的函数\u sign
可以如下所示:
_sigIn: function(e) {
var value = this.getAttr(e, "arg");
console.log(value);
}
非常感谢@KubaŠimonovský,第二种选择对我来说更好,效果也更好。这真是帮了大忙。:)
getAttr: function(e,attr) {
elem = e.target;
while (elem.parentNode != undefined) {
if (elem.getAttribute(attr) != undefined) {
return elem.getAttribute(attr);
}
elem = elem.parentNode;
}
},
_sigIn: function(e) {
var value = this.getAttr(e, "arg");
console.log(value);
}