2014-09-10 43 views
2

直到聚合物0.10.1 @published註釋在它聲明的Polymer元素上創建了一個屬性。
這改變了聚合物0.11.0。從那時起,需要@PublishedProperty(reflect: true)才能將字段值作爲屬性提供。@observable和@published之間有什麼區別

看來,由於此更新@published@observable具有相同的效果。我錯過了什麼嗎?

+1

你必須在'@ tenured'之​​前擁有'@ published'。 – 2014-09-10 16:18:55

+0

也許:-)。 。 – 2014-09-10 16:21:45

回答

2

@published屬性仍然允許您以聲明方式將該值用作HTML中的屬性本身。也就是說,你仍然可以做:

<my-element myprop="{{hello}}"></my-element> 

的變化是,通過attributes財產在程序訪問該值,則必須包括@PublishedProperty(reflect: true)。 (這似乎不是,如果你是直接與CustomTag類互動是這樣

需求@PublishedProperty(reflect: true)

var x = querySelector('x-foo'); 
x.bar = "hi"; 
// ... 
print(x.attributes["bar"]); 

這也需要@PublishedProperty(reflect: true)

/* CSS */ 
x-foo[bar="hi"] { background-color: blue; } 

這不:

XFoo x = querySelector('x-foo'); 
x.bar = "hi"; 
... 
print(x.bar); 

這是從討論中推斷的g roup for New Polymer Release 0.12.0

+0

太棒了!感謝您的鏈接。我想我需要再次閱讀這個討論。直接與CustomTag類交互不需要任何註釋,現有字段就足夠了。 – 2014-09-10 16:24:49

+0

您認爲如果'reflect:true'是默認值,並且參數註釋將用於另一種情況'@PublishedProperty(reflect:false)',那麼它會更方便嗎?我想這是以這種方式使用的,因爲'reflect:true'也用於Polymer.js。自從引入此更改後,我不需要發佈具有'reflect:false'的屬性。 – 2014-09-10 16:29:13

+0

個人而言,我很少使用'屬性'與我的組件進行交互,只是以聲明方式綁定兩種方式。所以我根本不需要'@PublishedProperty(反映:true)'。 – 2014-09-10 16:49:15

相關問題