Polymer 1.0 Paper-Radio-Group选择-如何获取所选项目 [英] Polymer 1.0 paper-radio-group selection - how to get selected item
问题描述
我尝试了此解决方案,但看起来像对我无能为力我有聚合物1.0.
I have tried this solution but seems like it is doing nothing for me. I have Polymer 1.0.
我从解决方案中所做的唯一更改是将observers
放在data
属性中,并且进行了未保护".我是从此处获得的.
Only change I made from the solution is to put the observers
inside data
property and made is "not protected". I got this idea from here.
最初,我使用Ricky解决方案中的确切方法,但这对我也不起作用.
Initially I used the exact approach as in Ricky's solution but that didn't work for me either.
这是我的自定义元素的外观:
Here is how my custom element looks like:
<dom-module id="radio-group-binder">
<template>
<paper-radio-group class="layout vertical" selected-item="[[selectedItem]]">
<template is="dom-repeat" items="[[data]]">
<paper-radio-button name="{{item.model}}" model$="[[item.model]]" price$="[[item.price]]"><span>[[item.model]]</span> <div class="paper-font-caption"><span>[[item.price]]</span> SEK</div></paper-radio-button>
</template>
</paper-radio-group>
<paper-item><span>[[model]]</span></paper-item>
<paper-item><span>[[price]]</span></paper-item>
</template>
<script>
(function () {
'use strict';
Polymer({
is: 'radio-group-binder',
properties: {
data: {
type: Array,
notify: true,
observers: ['selectedItemChanged(selectedItem)']
},
price: {
type: String,
notify: true
},
model: {
type: String,
notify: true
}
},
selectedItemChanged: function (el) {
this.price = el.getAttribute('price');
this.model = el.getAttribute('model');
},
});
})();
</script>
</dom-module>
如果我理解正确,那么每个paper-item
下的[[model]]
和[[price]]
之类的变量都应替换为选定的值.
If I have understood right, then variables like [[model]]
and [[price]]
under each paper-item
should get replaced by selected values.
我在selectedItemChanged
函数中尝试了一个警报,以检查它是否至少被调用了,但我什么也没得到.
I tried an alert inside the selectedItemChanged
function to check whether it is at least being called but I got none.
同样,在此帖子中,我注意到了Polymer version 1.0.2
被提及,并且此修复程序已在此处介绍.这是我面临的问题吗?如果是这样,我如何升级到该版本?如果不是这种情况,请让我知道我在做什么错.
Again, in this post I noticed that Polymer version 1.0.2
is mentioned and this a fix has been introduced here. Is this the issue I am facing? If so, how can I upgrade to this version? If this not the case then please let me know what wrong I am doing.
推荐答案
没有属性的observers
字段.您要么必须使用单个observer
属性(请参见 )或类"本身上的observers
字段(请参见
There is no observers
field for a property. You either have to use a single observer
property (see here) or a an observers
field on the "class" itself (see here):
properties: {
data: {
type: Array,
notify: true,
},
},
observers: ['selectedItemChanged(selectedItem)']
这篇关于Polymer 1.0 Paper-Radio-Group选择-如何获取所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!