簡體   English   中英

中的聚合物子特性<dom-repeat>

[英]Polymer sub-properties in <dom-repeat>

在“ dom-repeat”上的聚合物文檔中說:

項目子屬性更改的通知將轉發到模板實例,該模板實例通過常規結構化數據通知系統進行更新。

我認為這意味着如果更改數組的一個元素,它將更新所有綁定的元素。 我發現情況並非如此。 考慮到這一點,似乎更新子屬性的唯一選擇是使用數組方法或自定義函數重建數組,這對於大數據將越來越困難。 或以某種方式將觀察者添加到所有子屬性中,這並不高效。 有什么建議么?

無效的示例: http : //jsbin.com/wadeju/1/edit?html,輸出

(function(){
  Polymer({
    is: 'x-element',
    properties:{
      d:{
        type: String,
        value:"Click Me"
      },
      days:{ 
        type: Array,
        value: ["one", "two", "three"]
      }
    },
    c:function(){
        this.days[0] = "1";
        this.days[1] = "2";
        this.days[2] = "3";
        this.d="hello";
     },
  });

有效的示例: http : //jsbin.com/luqudo/edit?html,輸出

Polymer({
        is: 'x-element',
        properties:{
          d:{
            type: String,
            value:"Click Me"
          },
          days:{ 
            type: Array,
            value: ["one", "two", "three"]
          }
        },
        c:function(){
            this.days = ["1", "2", "3"]
            this.d="hello";
         },
      });
    })();

綁定數組值的推薦方法:
https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#array-binding

請注意, dom-repeat示例還將數組中的命名對象用於綁定。

您應該使用Polymer的(數組)變異方法來保持同步:
https://www.polymer-project.org/1.0/docs/devguide/properties.html#array-mutation

僅使用Polymer的屬性突變設置數據的示例:
http://jsbin.com/zuhecovequ/1/edit?html,輸出

(function(){
  Polymer({
    is: 'x-element',
    properties:{
      d:{
        type: String,
        value:"Click Me"
      },
      days:{ 
        type: Array,
        value: ["one", "two", "three"]
      }
    },
    c:function(){
        this.set("days.0","1");
        this.set("days.1","2");
        this.set("days.2","3");
        this.d="hello";
     },
  });
})();

暫無
暫無

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

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