2011-11-28 67 views

回答

1

(假設煎茶觸摸的1.x)

據我所知是沒有的事件,告訴您的數據將被改變,但還沒有發生變化。 但是,變更後事件被稱爲「datachanged」。如果您只需要知道您的數據已更改(而不是在更改之前),請爲此「datachanged」事件添加一個偵聽器,並丟棄我已寫入的其他數據。

但是,如果你真的需要一個「beforedatachanged」事件,請繼續閱讀:

您可以實現自己的事件(並將其命名爲「beforedatachanged」)通過使用Ext.override覆蓋煎茶行爲,並觸發數據實際更改前的新事件。

這聽起來很難,但它確實不是:

首先檢查了這一點: http://docs.sencha.com/touch/1-1/source/AbstractStore.html 去找「onBatchComplete」,你會看到,它激發了「datachanged」事件:

/** 
* @private 
* Attached as the 'complete' event listener to a proxy's Batch object. Iterates over the batch operations 
* and updates the Store's internal data MixedCollection. 
*/ 
onBatchComplete: function(batch, operation) { 
    var operations = batch.operations, 
     length = operations.length, 
     i; 

    this.suspendEvents(); 

    for (i = 0; i < length; i++) { 
     this.onProxyWrite(operations[i]); 
    } 

    this.resumeEvents(); 

    this.fireEvent('datachanged', this); 
}, 

在「this.suspendEvents();」之前你必須解僱你自己的自定義事件,因爲在那之後,這些操作就被執行了。

要覆蓋此,寫這樣的事情在你的應用程序:

Ext.override(Ext.data.AbstractStore, 
{ 
    onBatchComplete: function(batch, operation) 
    { 
     var operations = batch.operations, 
      length = operations.length, 
      i; 

     this.fireEvent('beforedatachanged', this); 

     this.suspendEvents(); 

     for (i = 0; i < length; i++) { 
      this.onProxyWrite(operations[i]); 
     } 

     this.resumeEvents(); 

     this.fireEvent('datachanged', this); 
    }, 
}); 

然後,你需要聽你的模型代碼的beforedatachanged事件和你所有的設置。