我使用聚合物0.5,特别是核心选择器元素:
<core-selector multi valueattr="label" id="specialisms" layout horizontal wrap around-justified>
<div class="item core-selected" label="label1" active>Boo</div>
<div class="item core-selected" label="label1" active>Baa</div>
<div class="item" label="label1">Cow</div>
</core-selector>
如何使用数组提供多个选定值?这样做的最佳方式是什么?
是否可以像这样输入密钥:
选择= “[ 'KEY1', 'KEY2', 'KEY3']”
提前致谢
答案 0 :(得分:1)
使用multi-selection
<强> HTML 强>
<core-selector selected="{{multiSelected}}" multi>
<div>Item 0</div>
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
</core-selector>
<强>的Javascript 强>
Polymer({
ready: function() {
this.multiSelected = [0,1,2];
}
});
或当您不使用自定义元素时
<script>
document.addEventListener('polymer-ready', function(e) {
var tmp = document.querySelector('#template');
tmp.multiSelected = [0,1,2];
});
</script>
selected
属性采用数组索引数组