如何使用聚合物在多维对象中添加值?

时间:2016-06-08 18:20:46

标签: polymer polymer-1.0

我是聚合物的新手,我对这个工具有严重的问题,最近尝试在多维对象中添加元素。

我声明了一个对象如下:

tabArrayTest: {
      type: Object,
      value: [{
                tabName:"visita1",
                inputs: [{value:"", placeholder:"t1_input1"}]

              },
              {
                tabName:"visita2",
                inputs: [{value:"", placeholder:"t2_input1"}]
              },
              {
                tabName:"visita3",
                inputs: [{value:"", placeholder:"t3_input1"}]
              },
                  {
                tabName:"visita4",
                inputs: [{value:"", placeholder:"t4_input1"}]
              }]
    }

我想实现一个允许我在所选对象的输入中添加新元素的函数。结果是这样的:

tabArrayTest: {
      type: Object,
      value: [{
                tabName:"visita1",
                inputs: [{value:"", placeholder:"t1_input1"},{value:"", placeholder:"t1_input2"},{value:"", placeholder:"t1_input3"}]

              },
              {
                tabName:"visita2",
                inputs: [{value:"", placeholder:"t2_input1"}]
              },
              {
                tabName:"visita3",
                inputs: [{value:"", placeholder:"t3_input1"}]
              },
                  {
                tabName:"visita4",
                inputs: [{value:"", placeholder:"t4_input1"}]
              }]
    }

这可能吗?,怎么样?

1 个答案:

答案 0 :(得分:1)

您应该使用聚合物array mutation methods

之一

例如:

pushInputToTab: function (tabIndex, newInput) {
    this.push('tabArrayTest.' + tabIndex + '.inputs', newInput);
}