[英]Is there a way to listen silent events on backbonejs?
I'm trying to listen backbone's model's ´changed´-event for certain attribute, like 我正在尝试侦听骨干模型的“更改”事件的某些属性,例如
this.listenTo(this, 'change:someAttr', this.eventListener);
However, it is changed silently, so normal event listening does not work. 但是,它被无提示更改,因此正常事件侦听不起作用。 Is there a way to listen backbone's silent events? 有没有办法听骨干的静默事件?
The only way I can think of is via some sort of "polling", ie checking over and over via a setInterval. 我能想到的唯一方法是通过某种“轮询”,即通过setInterval反复检查。
initialize: function() {
this.listenSilent();
},
listenSilent: function() {
var startVal = this.get('myAttr');
var that = this;
var silentListener = setInterval(function() {
if (that.get('myAttr') !== startVal) {
that.trigger('myevent'); // any custom event name that you can listen to
stopInterval(silentListener);
that.listenSilent();
}
}, 100);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.