2017-08-16 13 views
0

ポリマーに新しくなりません。お互いに通信する2つの異なるポリマー成分を使用している。私はそれを2回(2×2コンポーネント)行う必要があります。同じページでポリマー成分のペアを2回使用すると、

次のコードでは、さまざまなコンポーネントのひとつペアを使用し、それが動作します:

<dom-bind id="dombind"> 
    <template is="dom-bind"> 

    <polymer-componentA id="polymercomponentA_1" 
     attribute="[[x]]" 
     attribute="[[x]]" 
     attribute="{{x}}"> 
    </polymer-componentA> 
    <polymer-componentB id="polymer-componentB_1" 
     attribute="{{x}}"> 
    </polymer-componentB> 

    </template> 
</dom-bind> 

しかし、私はコンポーネントの他のペアを追加するとき、それは悪い作業を開始します。私はこれはよくやっていないけど、私はこれについての良い例を見つけるいけない

<dom-bind id="dombind"> 
    <template is="dom-bind"> 

    <polymer-componentA id="polymercomponentA_1" 
     attribute="[[x]]" 
     attribute="[[x]]" 
     attribute="{{x}}"> 
    </polymer-componentA> 
    <polymer-componentB id="polymer-componentB_1" 
     attribute="{{x}}"> 
    </polymer-componentB> 

    </template> 
</dom-bind> 

<dom-bind id="dombind"> 
    <template is="dom-bind"> 

    <polymer-componentA id="polymercomponentA_2" 
     attribute="[[x]]" 
     attribute="[[x]]" 
     attribute="{{x}}"> 
    </polymer-componentA> 
    <polymer-componentB id="polymer-componentB_2" 
     attribute="{{x}}"> 
    </polymer-componentB> 

    </template> 
</dom-bind> 

:私は、彼らが同じコンポーネントを(代わりに独立しているの)使用と思います。 2つのポリマコンポーネントを使用する正しい方法は何ですか? ありがとうございます!

+0

それはフィドルやあなたが直面しているどのようなエラーで表示することは可能ですか? – Ofisora

+0

それは大きなプロジェクトですが、私は試してみます。私は属性が両方のコンポーネントの間で混在していると思う。 – Rashomon

+1

両方とも同じ属性を使用しているので、変更すると他のものにも反映されます。あなたは何を達成しようとしていますか?参照してください。 – Ofisora

答えて

2

If you provide a function, Polymer calls the function once per element instance.

When initializing a property to an object or array value, use a function to ensure that each element gets its own copy of the value, rather than having an object or array shared across all instances of the element.

出典:https://www.polymer-project.org/2.0/docs/devguide/properties#configure-values

static get properties() { 
    return { 
     data: { 
     type: Object, 
     value: function() { return {}; } 
     } 
    } 
    } 
+0

エラーが発生しました: 'Uncaught TypeError: 'children' of null'プロパティを読み取れません。 属性の名前を変更しようとしている可能性があります – Rashomon

+1

この解決策が最後に機能しました。ありがとうございました!他に問題があった – Rashomon

関連する問題