簡體   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