Polymer 聚合-从if模板中选择DOM元素
我在学聚合物。我有一个如下设置的视图:Polymer 聚合-从if模板中选择DOM元素,polymer,Polymer,我在学聚合物。我有一个如下设置的视图: Polymer({ ... onButtonClick: function() { // The this.root here refers to the local dom // It is highly advised that you use Polymer.dom(<node>) when doing dom manipulations Polymer.dom(this.root).querySelect
Polymer({
...
onButtonClick: function() {
// The this.root here refers to the local dom
// It is highly advised that you use Polymer.dom(<node>) when doing dom manipulations
Polymer.dom(this.root).querySelector('#myComponent').test();
}
});
my-view.html
我的挑战是,如果我的组件不在IF模板中,我的方法就可以工作。当我的组件位于if模板内时,我会得到一个错误,该错误表示:
TypeError: Cannot read property 'test' of undefined
我做错了什么
注意:使用数据绑定动态创建的节点,包括dom repeat和dom(如果未将模板添加到this.$hash中)中的节点。哈希仅包括静态创建的本地DOM节点,即元素最外层模板中定义的节点
资料来源:
由于您已经向按钮上的单击事件添加了一个侦听器,因此可以按如下方式重新定义该侦听器:
Polymer({
...
onButtonClick: function() {
// The this.root here refers to the local dom
// It is highly advised that you use Polymer.dom(<node>) when doing dom manipulations
Polymer.dom(this.root).querySelector('#myComponent').test();
}
});
注意:使用数据绑定动态创建的节点,包括dom repeat和dom(如果未将模板添加到this.$hash中)中的节点。哈希仅包括静态创建的本地DOM节点,即元素最外层模板中定义的节点
资料来源:
由于您已经向按钮上的单击事件添加了一个侦听器,因此可以按如下方式重新定义该侦听器:
Polymer({
...
onButtonClick: function() {
// The this.root here refers to the local dom
// It is highly advised that you use Polymer.dom(<node>) when doing dom manipulations
Polymer.dom(this.root).querySelector('#myComponent').test();
}
});
聚合物有这个简单的功能
this.$$('#myComponent')
聚合物有这个简单的功能
this.$$('#myComponent')
令人惊叹的非常感谢你的帮助!令人惊叹的非常感谢你的帮助!