我正在加载聚合物中的一个单选按钮组,带有一组4个单选按钮作为问题的答案选项。我有4个问题。现在,如果我在第一个问题中选择一个选项并选择下一个(转到下一个问题),则第二个问题已选择其选项(与第一个问题相同)。为什么会这样?
<paper-radio-group>
<template is="dom-repeat" items=[[_calculateQuestionOptions(index)]]>
<paper-radio-button name="{{_calculateId(index)}}">
[[item.questionOption]]
</paper-radio-button><br>
</template>
</paper-radio-group>
下一步和上一步操作的代码
next() {
if (this.index < this.repos.length-1) {
this.index +=1;
}
}
prev() {
if (this.index>0) {
this.index -= 1;
}
}
解决这个问题。我想将所有答案添加到数组中,并在单击下一个按钮后立即清除选择。像这样的东西。
next() {
var questionId = this.repos[this.index].questionId;
if (Polymer.dom(this.root).querySelector("paper-radio-group")) {
this.answers[questionId] = Polymer.dom(this.root).querySelector("paper-radio-group").selected;
Polymer.dom(this.root).querySelector("paper-radio-group").selected = null;
}
if (this.index < this.repos.length-1) {
this.index +=1;
}
questionId = this.repos[this.index].questionId;
if (this.answers[questionId] !== null) {
Polymer.dom(this.root).querySelector("paper-radio-group").selected = this.answers[questionId];
}
}
这是唯一的方法还是有更好的方法来做到这一点。