在polymer 0.5,this.templateInstance.model
提供了一種訪問在包含is="auto-binding"
(或任何其他)this
模板的範圍中定義的屬性的方式。在Polymer 1.0中的templateInstance.model
現在,在聚合物1.0中訪問包含is="dom-bind"
(或任何其他)模板的屬性的等效方式是什麼?
編輯:
例如,在兩個元件<my-el-a>
和<my-el-b>
下面的代碼段打算分別將值設置爲包圍<template is="dom-bind">
的counterA
和counterB
性質。
<my-el-b>
通過反光屬性counter
(notify:true
)成功。
<my-el-a>
打算通過「父母」/ templateInstance.model
但這樣做失敗。這個用於在Polymer 0.5中工作。我如何才能在Polymer 1.0中工作?換句話說,templateInstance.model
的等價物是什麼?
<script>
! function() {
var counterA = 0;
Polymer({
is: 'my-el-a',
ready: function() {
counterA += 1;
this.instanceTemplate.model.counterA = counterA; //used to work in Polymer 0.5
}
})
}();
</script>
<script>
! function() {
var counterB = 0;
Polymer({
is: 'my-el-b',
properties: {
counter: {
value: 0,
type: Number,
notify: true
}
},
ready: function() {
counterB += 1;
this.counter = counterB;
console.log(this);
}
})
}();
</script>
<template is="dom-bind">
<div>CounterA: <span>{{counterA}}</span>
</div>
<div>CounterB: <span>{{counterB}}</span>
</div>
<my-el-a></my-el-a>
<my-el-b counter="{{counterB}}"></my-el-b>
</template>
剛纔我發現'dataHost',它完全適合我的需求。什麼是人們使用這種無證的功能的想法,這可能有風險嗎? – nverba