Polymer 聚合物数据绑定:在路径中使用属性?

Polymer 聚合物数据绑定:在路径中使用属性?,polymer,polymer-2.x,Polymer,Polymer 2.x,是否可以在下面标记为property的路径中使用属性 <template is="dom-if" if="[[one.two.PROPERTY.four]]"> ... </template> class MyTag extends Polymer.Element { static get is() {return 'my-tag'} static get properties() { return { PROPERTY: String

是否可以在下面标记为property的路径中使用属性

<template is="dom-if" if="[[one.two.PROPERTY.four]]">
 ...
</template>

class MyTag extends Polymer.Element {
  static get is() {return 'my-tag'}
  static get properties() {
    return {
      PROPERTY: String
    }
  }
}
customElements.define(MyTag.is, MyTag)

实际上有一种方法是有效的。但是,这太粗糙了,您不应该在生产代码中使用它。如果这是共享的,那就太糟糕了,如果您的代码可能会增长,那么您可能会对它产生不希望的副作用。

以下是我要做的和需要做的。现在在模板中,第一个将变成1.2.foo.4,第二个将变成1.2.bar.4。@Sunny我想你不应该这么疯狂,相信我,Polymer是一个非常严密的框架,但当你试图开始制定自己的规则时,它偶尔会开始不以你期望的方式响应。我接受了你的建议,决定采用一种更基本/冗余的方法,因为似乎没有一种简单的方法来创建动态路径。谢谢
<dom-module id="my-tag">
  <template>
    <template is="dom-if" if="{{_ifFour}}">
      <b>yo</b>
    </template>
  </template>

  <script>
  class TestElement extends Polymer.Element {

    static get is() { return 'my-tag' }

    static get properties () {
      return {
        PROPERTY: {
          type: String,
          value: 'initial',
          observer: '_PROPERTYChanged'
        },

        one: {
          type: Object,
          value: function () {
            return {
              two: {}
            }
          }
        },

        _ifFour: {
          type: Boolean,
          value: false
        }
      }
    }

    static get observers () {
      return ['_computeIfFour(one.*)']
    }

    _computeIfFour () {
      if (this.one.two[this.PROPERTY] === undefined)
        this._ifFour = false;

      this._ifFour = this.one.two[this.PROPERTY].four;
    }

    _PROPERTYChanged (propertyName, old) {
      if (old) {
        delete this.one.two[old];
      }
      this.one.two[propertyName] = {
        four: ''
      }
    }

  }

  customElements.define(MyTag.is, MyTag)
  </script>
</dom-module>