多路径对象数组变异

multi path Array of objects mutation

想要改变 Obj 数组的路径。

对象应该在点击时改变,看起来像这样:

<iron-icon id="id" icon="icons:arrow-downward" on-click="_sortTags"
class$="arrow [[sortData.id.icon]] [[sortData.id.state]]"></iron-icon>

这里我想改变 sortData Obj,这个函数在点击上面的图标时被触发

_changeSortData(field,order,iconShape,status){ //there is a function calls this function but did not bring it here to make issue simple
        this.set('sortData[field].sort', order);
        this.set('sortData[field].icon', iconShape);
        this.set('sortData[field].state', status);

      }

下面的对象是 属性:

sortData: {
          type: Object,
          value: function () {
            return {
              "id": {
                "icon": "downward",
                "sort": "default",
                "state": "inactive"
              },
              "date": {
                "icon": "downward",
                "sort": "default",
                "state": "inactive"
              }
            }
          },
        },

现在是否可以在此处转义单个 qoutes 以便将 [field] 应用为婴儿车

this.set('sortData[field].sort', order);

因为sortData Obj中有两个字段(id和data)

this.set(path, value)中,path可以指定为stringArray。由于您有一个动态路径部分,您可以使用这样的 Array 路径:

this.set(['sortData', field, 'sort'], order); // `field` is dynamic

demo