簡體   English   中英

聚合物dom-repeat子屬性將子節點更改為主機接線

[英]Polymer dom-repeat sub property changes child to host wiring

我有一個將對象與子元素綁定在一起的主機元素綁定數組,該子元素具有用於編輯其屬性的paper-input 我看不到主機div元素中反映的輸入值變化。 即使在調試時,我也可以看到主機對象具有最新編輯的name 我該怎么做才能自動連線?

    <!-- Host element -->
<dom-module id="host-item">
    <template>
          <div>
             <div>[[selectedEmployee.name]]</div>
                <template is="dom-repeat" items="[[employees]]" as="employee">
                    <item-edit item="[[employee]]"></item-edit>
                </template>
          </div>
    </template>
    <script>
    Polymer({
                is: 'host-item',
                properties: {                
                    selectedEmployee: {
                        type: Object 
                    },
                    employees: {
                      type: Array,
                      value = [ { name: 'Name 1'}, { name: 'Name 2'}, { name: 'Name 2'}]
                    }
                },
                ready: function() {
                  this.selectedEmployee = this.employees[0];
                }
            }); 
    </script>
</dom-module>

<!-- Child element -->
<dom-module id="item-edit">
    <template>
          <paper-input id="input" value="{{item.name}}" error-message="Invalid name!"></paper-input>            
    </template>
    <script>
    Polymer({
                is: 'item-edit',
                properties: {                
                    item: {
                        type: Object
                    }
                }
            }); 
    </script>
</dom-module>

使用{{employee}}進行雙向綁定 [[...]]僅限於一種方式。 在屬性定義上使用notify:true

子元素應該在父元素之前定義。

這是Plunk的工作示例,以及類似的Plunk

<item-edit item="{{employee}}"></item-edit>
...
employee: {
                type: Object,
                notify: true,
                value: function () { return {name: 'Test' }; }
            }

更新:

現在,“員工”數據采用對象數組的形式。 查看這個問題以使用數組: 聚合物,問題與綁定數組到紙張滑塊值

普拉克

文檔: 綁定到數組項

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM