2014-07-06 28 views
1

如何訪問我的自定義元素的ready:function中的已發佈屬性。我可以得到它,如果有人通過它,但我想再次檢查默認值。 I.e .:在就緒中訪問發佈屬性:函數

Polymer('post-card', { 
    publish: { 
     inline : false 
    }, 
    ready:function(){ 
       // returns what's passed in 
      var passedIn = this.getAttribute('inline'), 

       // returns null when inline is not present on the element 
       default = this.getAttribute('inline') ; 
    } 
}); 

我知道默認變量是在elemnt上尋找屬性「inline」。我的問題是,如何訪問我在發佈對象下設置的默認值?

在先進的感謝:)的時間

回答

2

95%,你應該使用聚合物和公佈屬性時,再也不需要getAttribute。已發佈的屬性作爲this上的屬性進行訪問。在你的元素的背景下,this是元素。要檢查默認值,可以這樣做:

(function() { 
    var INLINE_DEFAULT = false; 

    Polymer('post-card', { 
    publish: { 
     inline: INLINE_DEFAULT 
    }, 
    ready: function() { 
     console.log(this.inline === INLINE_DEFAULT); 
    } 
    } 
}(); 
相關問題