Polymer 无法查询dom重复中的元素以设置单选按钮默认值
聚合物1* 我试图在一系列生活在dom repeat中的Polymer 无法查询dom重复中的元素以设置单选按钮默认值,polymer,polymer-1.0,radio-group,Polymer,Polymer 1.0,Radio Group,聚合物1* 我试图在一系列生活在dom repeat中的纸质无线电组元素中设置默认值 填写表单后,addFormData函数工作正常……它可以毫无问题地查询元素 但是当表单第一次加载时,我无法查询setRadioDefaults()函数中的元素。。。radiogroup节点列表只是一个空数组。这不是比赛条件,因为我尝试设置超时,但仍然没有成功。你知道为什么吗 addFormData: function(body) { // WORKS GOOD, IT FINDS THE E
纸质无线电组元素中设置默认值
填写表单后,addFormData
函数工作正常……它可以毫无问题地查询元素
但是当表单第一次加载时,我无法查询setRadioDefaults()
函数中的元素。。。radiogroup
节点列表只是一个空数组。这不是比赛条件,因为我尝试设置超时,但仍然没有成功。你知道为什么吗
addFormData: function(body) {
// WORKS GOOD, IT FINDS THE ELEMENTS
var radioGroups =
this.$$('#activeForm').querySelectorAll('paper-radio-group');
var radioGroupsArray = Array.prototype.slice.call(radioGroups);
return radioGroupsArray.map(function(radioGroup) {
var fieldID = radioGroup.attrForItemTitle;
var value = radioGroup.selected;
return {
field_id: fieldID,
value: value
};
});
},
setRadioDefaults: function() {
Polymer.dom.flush();
// WORKS BAD, DOES NOT FIND THE ELEMENTS
var radioGroups =
this.$$('#activeForm').querySelectorAll('paper-radio-group');
radioGroups.forEach(function(radio) {
radio.selected = this.noData;
});
},
[[item.field_标签]]
--------------------
setRadioDefaults:function(){
console.log('aaa');
Polymer.dom.flush();
向量放射群=
Polymer.dom(this.root).queryselectoral('paper-radio-group');
控制台日志(组);
RadioGroup.forEach(功能(收音机){
radio.selected=this.complete;
},本页)
您正在通过Polymer 1.x将项目移动到ShadyDom中,因此您需要应用Polymer.dom()
以确保捕获其中的所有更改,请尝试Polymer.dom(this.root).querySelectorAll('paper-radio-group');
捕获这些元素。例如:
<link rel="import" href="https://polygit.org/polymer+^1.9.1/webcomponentsjs+^0.7.0/components/polymer/polymer.html">
<dom-module id="configurable-name-tag">
<template>
<!-- bind to the "owner" property -->
<template on-dom-change="doStuff" is="dom-repeat" items="[[items]]">
<div>[[item]]</div>
</template>
</template>
<script>
Polymer({
is: "configurable-name-tag",
properties: {
// declare the owner property
items: {
type: Array,
value: function() {
return [1,2,3,4];
}
}
},
doStuff: function() {
Polymer.dom.flush();
alert(Polymer.dom(this.root).querySelectorAll('div').length);
}
});
</script>
</dom-module>
[[项目]]
聚合物({
是:“可配置名称标签”,
特性:{
//申报业主财产
项目:{
类型:数组,
值:函数(){
返回[1,2,3,4];
}
}
},
doStuff:function(){
Polymer.dom.flush();
警报(Polymer.dom(this.root).querySelectorAll('div').length);
}
});
能否显示包含纸质无线电组的模板以及调用setRadioDefaults()
的代码?@tony19我将setRadioDefaults()
函数移动到包含无线电组的元素中。但运行this.$$('#activeForm')。setRadioDefaults()时仍然会得到一个空节点列表
从外部
<link rel="import" href="https://polygit.org/polymer+^1.9.1/webcomponentsjs+^0.7.0/components/polymer/polymer.html">
<dom-module id="configurable-name-tag">
<template>
<!-- bind to the "owner" property -->
<template on-dom-change="doStuff" is="dom-repeat" items="[[items]]">
<div>[[item]]</div>
</template>
</template>
<script>
Polymer({
is: "configurable-name-tag",
properties: {
// declare the owner property
items: {
type: Array,
value: function() {
return [1,2,3,4];
}
}
},
doStuff: function() {
Polymer.dom.flush();
alert(Polymer.dom(this.root).querySelectorAll('div').length);
}
});
</script>
</dom-module>