【发布时间】:2016-07-19 20:52:11
【问题描述】:
这是问题的示例: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) 元素也可以用于此任务。
【问题讨论】:
-
我不明白,如果你改变纸滑块的最大值,它会改变最大值..有什么问题??在你的例子中,一切看起来都很好。
-
据我所知,这是因为初始值,它与最大值无关。如果您将初始值更改为例如 15,您会注意到它会在将其更改为 31 时更新,但在将其更改为 15 时不会更新。
-
@jdepypere 正确,我已经编辑了问题。
标签: data-binding polymer polymer-1.0