最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Polymer option selected - Stack Overflow

programmeradmin2浏览0评论

How do I set select option selected in Polymer 1.0?

<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>

How do I set select option selected in Polymer 1.0?

<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>
Share Improve this question edited Aug 26, 2015 at 16:43 user913129 asked Aug 26, 2015 at 16:10 user913129user913129 992 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You were very close. Use this.

<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,"yourtypetopare")}}">{{type}}</option>
  </template>
</select>

Now, add a function in your polymer's element.

  selected: function(item, type){
    return type == item.type;
  },
发布评论

评论列表(0)

  1. 暂无评论