触发点击功能时,它会捕获并记录以前的值。
如果{{item.authd}}
设置为authnr
,其单选按钮会突出显示,但是当点按其他按钮时,e.currentTarget.selected
会显示较旧的值,而不是点按的?
<template is="dom-repeat" items="{{data}}">
<paper-radio-group selected="{{item.authd}}" on-tap="authChanged" id="{{item.id}}">
<paper-radio-button name="authnr">N/R</paper-radio-button>
<paper-radio-button name="pending">Pending</paper-radio-button>
<paper-radio-button name="authd">Auth</paper-radio-button>
</paper-radio-group>
</template>
authChanged: function(e, name) {
console.log(e.currentTarget.selected) // shows old value, not tapped value
}
答案 0 :(得分:0)
请看下面的代码:
<dom-module id="x-test">
<template>
<template is="dom-repeat" items="[[data]]">
<paper-radio-group attr-for-selected="name" selected="{{item.authd}}" on-tap="authChanged" id="{{item.id}}">
<paper-radio-button name="authnr">N/R</paper-radio-button>
<paper-radio-button name="pending">Pending</paper-radio-button>
<paper-radio-button name="authd">Auth</paper-radio-button>
</paper-radio-group>
</template>
</template>
<script>
Polymer({
is: 'x-test',
properties: {
data: {
type: Array,
value: function() {
return [
{authd: 'authnr',id: 1},
{authd: 'pending', id:2},
{authd: 'authd', id:3}
]
}
},
},
authChanged: function(e, name) {
this.async(function() {
var model = e.model.item;
console.log(model.authd, model.id);
});
}
});
</script>
</dom-module>
我已将attr-for-selected
添加到广播组,以确定选择了哪个广播按钮。
在authChanged
回调中,我使用async
方法确保在我们检查模型中的当前项之前selected
值已更改。