选择聚合物选项

Polymer option selected

如何在 Polymer 1.0 中设置 select 选项 select?

<select id="typeSelect" style="width:100%;" value="{{item.type::change}}">
  <option value="">Choose a type</option>
  <template is="dom-repeat" items="{{types}}" as="type" >
    <option selected?="{{type==item.type}}">{{type}}</option>
  </template>
</select>

你们非常亲密。使用这个。

<select id="typeSelect" style="width:100%;" value="{{item.type::change}}">
  <option value="">Choose a type</option>
  <template is="dom-repeat" items="{{types}}" as="type" >
    <option selected$="{{selected(type,"yourtypetocompare")}}">{{type}}</option>
  </template>
</select>

现在,在您的聚合物元素中添加一个函数。

  selected: function(item, type){
    return type == item.type;
  },