@observable
只對吸氣劑是必要的。
我猜你想要做的是
// additional functionality in the setter
String _counter = '00:00';
@PublishedProperty(reflect: true)
String get counter => _counter;
void set counter (String s){
_counter = s;
// do something ...
}
void attached() {
new async.Timer.periodic(new Duration(seconds:1), (_) {
var oldVal = _counter;
var time = new DateTime.now();
_counter = '${time.minute}:${time.second}';
// explicitely notify Polymer about the changed value
notifyPropertyChange(#counter, oldVal, _counter);
});
}
或可替代
// additional functionality in xxxChanged
@PublishedProperty(reflect: true)
String counter = '00:00';
void counterChanged(oldVal, newVal){
// do something ...
}
另一個是
// use readValue/writeValue to fix some timing issues
@PublishedProperty(reflect: true)
String get counter => readValue(#counter);
void set counter (String s){
writeValue(#counter, s);
// do something ...
}
//in the constructor
writeValue(#counter, '00:00');
@PublishedProperty(reflect: true)
確保HTML屬性獲取與更新字段值。
如果你覺得這混亂的,你並不孤單...... 3個解決方案,我只能得到,如果我用中間的一個它的工作的
,只有當我設置現場'@ published'我不能讓任何人用'@PublishedProperty()' – 0xor1 2014-08-31 14:08:14
我在第一個例子中忘記了一些東西('notifyPropertyChange'),否則這對我有用。你使用什麼聚合物版本? – 2014-08-31 15:05:25
我使用聚合物0.11.0 + 5 – 0xor1 2014-09-02 19:49:37