下面是示例的問題的:Plunk聚合物,發出帶有結合陣列紙滑塊值
的初始值,31,改變滑塊時,不結合。 數組值31在啓動時就位,但不能在更改後重新安裝。
如何正確地將滑塊綁定到數組?
<base href="http://polygit.org/polymer+:master/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="polymer/polymer.html" rel="import">
<link href="paper-input/paper-input.html" rel="import">
<link href="paper-slider/paper-slider.html" rel="import">
<link href="google-chart/google-chart.html" rel="import">
<dom-module id="dynamic-chart">
<template>
Binded values:
<br>
arrayItem: {{arrayItem(rows.*, 0, 1)}}
<br>
arrayBase: {{arrayBase(rows.*)}}
<hr>
Jan slider:
<paper-slider min="1"
max="31"
value="{{rows.0.1}}"
pin
editable>
</paper-slider>
</template>
<script>
Polymer({
is: 'dynamic-chart',
properties: {
rows: {
type: Array,
notify: true,
},
},
//domReady:
attached: function() {
this.async(function() {
this.rows=[ ["Jan", 31],["Feb", 28],["Mar", 31] ];
console.log('domReady');
});
},
// first argument is the change record for the array change,
// change.base is the array specified in the binding
arrayItem: function(change, index, path) {
console.log('arrayItem');
return this.get(path, change.base[index]);
},
arrayBase: function(change) {
console.log('arrayBase');
return change.base;
},
});
</script>
</dom-module>
<dynamic-chart>
</dynamic-chart>
更新: array-selector(simple example)元件可以用於這個任務了。
我不明白,如果你改變最大紙滑塊它會改變最大..有什麼問題?你的例子中的 一切看起來都不錯。 – Alon
從我可以告訴這是因爲初始值,它與最大值無關。如果將初始值更改爲例如15,則會發現在將其更改爲31時會更新,但在將其更改爲15時不會更新。 – jdepypere
@jdepypere正確,我已編輯該問題。 –