Data binding 聚合物,绑定阵列到纸张滑块值的问题

Data binding 聚合物,绑定阵列到纸张滑块值的问题,data-binding,polymer,polymer-1.0,Data Binding,Polymer,Polymer 1.0,以下是问题的示例: 更改滑块时,初始值31不绑定。 数组值31位于初始化上,但更改后无法重置 如何将滑块正确绑定到阵列 <base href="http://polygit.org/polymer+:master/components/"> <script src="webcomponentsjs/webcomponents-lite.min.js"></script> <link href="polymer/polymer.html" rel="imp

以下是问题的示例:

更改滑块时,初始值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>

绑定值:

arrayItem:{{arrayItem(行。*,0,1)}
arrayBase:{{arrayBase(行。*}}
Jan滑块: 聚合物({ 是‘动态图表’, 特性:{ 行:{ 类型:数组, 通知:正确, }, }, //多姆雷迪: 附:函数(){ this.async(函数(){ 行=[“一月”,31],“二月”,28],“三月”,31]; log('domReady'); }); }, //第一个参数是数组更改的更改记录, //change.base是绑定中指定的数组 arrayItem:函数(更改、索引、路径){ console.log('arrayItem'); 返回这个.get(path,change.base[index]); }, arrayBase:函数(更改){ console.log('arrayBase'); 返回change.base; }, });
更新:
()元素也可用于此任务。

您正在尝试将数组的第一个元素
行绑定。0.1
是一个常量值,
31
与纸张滑块的
值绑定。
arrayItem
get在其值更改时通知正在发生的情况,即
!==31

您应该做的是像这样绑定
max
值。


一旦中的滑块发生更改,则无法将初始值31绑定回arrayItem:


绑定值:
arrayItem get在其值更改时发出通知,即!==31
arrayItem:{{arrayItem(行。*,0,1)}
arrayBase:{{arrayBase(行。*}} 纸张滑块1 行第一个元素:{{Rows.0.1}}==>常量值 纸张滑块值: 纸张滑块2 行第二个元素:{{Rows.1.1}}==>常量值 纸张滑块值: 聚合物({ 是‘动态图表’, 特性:{ 行:{ 类型:数组, 通知:正确, }, _价值2:{ 类型:数字, 值:0, 观察者:“\u值2已更改” } }, //您还可以使用observer而不是addEventListener _value2Changed:函数(val){ console.log(“这是纸张滑块#2值”+val); }, 就绪:函数(){ //纸张滑块#1的事件 document.querySelector('#ps1').addEventListener('value-change',函数(e){ document.querySelector(“#ps1Value”).textContent=e.target.value; }); //纸张滑块#1的事件 document.querySelector('#ps2').addEventListener('value-change',函数(e){ document.querySelector('#ps2Value').textContent=e.target.value; }); }, //多姆雷迪: 附:函数(){ this.async(函数(){ //一旦滑块更改,初始值31将无法返回: 该行=[ [“1月”,31日], [“2月28日], [“3月”,31日] ]; log('domReady'); //console.log(this.rows); }); }, //第一个参数是数组更改的更改记录, //change.base是绑定中指定的数组 arrayItem:函数(更改、索引、路径){ console.log('arrayItem'); //控制台日志(更改); //控制台日志(索引); //console.log(路径); //log(this.get(path,change.base[index]); //get(path,root)返回路径的值 //相对于根对象。 返回这个.get(path,change.base[index]); }, arrayBase:函数(更改){ console.log('arrayBase'); 返回change.base; }, });
我不明白,如果您要更改最大纸张滑块,它将更改最大。。有什么问题吗??在你的例子中,一切看起来都很好。从我可以看出这是因为初始值,它与最大值无关。如果您将初始值更改为eg 15,您会注意到它将在更改为31时更新,但在将其更改为15时不会更新。@jDepype更正,我已编辑了该问题。谢谢,它可以工作。谷歌图表需要数组作为参数,而不是对象。下面是一个例子: