繁体   English   中英

有没有一种方法可以侦听中枢静默事件?

[英]Is there a way to listen silent events on backbonejs?

我正在尝试侦听骨干模型的“更改”事件的某些属性,例如

this.listenTo(this, 'change:someAttr', this.eventListener);

但是,它被无提示更改,因此正常事件侦听不起作用。 有没有办法听骨干的静默事件?

我能想到的唯一方法是通过某种“轮询”,即通过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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM