如何爲Sencha Touch MVC模型調用beforeSave方法(即每次添加,更新和/或保存模型記錄時觸發的方法)?Sencha Touch MVC Model beforeSave
0
A
回答
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事件和你所有的設置。
相關問題
- 1. CakePHP 2.9.7 Model :: beforeSave()
- 2. Sencha Touch MVC最佳實踐
- 3. Sencha Touch查詢
- 4. Sencha touch 2.製作MVC網格
- 5. Sencha Touch JSONPReader
- 6. Sencha Touch XML
- 7. 定義新的xtype字段sencha touch MVC
- 8. Sencha Touch 2 MVC列表事件接線
- 9. Sencha Touch XML列表
- 10. 總價值Sencha Touch
- 11. Sencha Touch 2 vs DHTMLX Touch
- 12. Sencha Touch:按鈕
- 13. Sencha Touch fireEvent
- 14. Sencha Touch和PhoneGap
- 15. Sencha Touch入門
- 16. Ext.Ajax.request Sencha Touch
- 17. sencha-touch using ActionSheet
- 18. Sencha Touch 2 Ext.util.Geolocation
- 19. sencha touch Ext.Router
- 20. Cordova和Sencha Touch
- 21. Sencha Touch Watermark
- 22. Sencha Touch itemtap
- 23. Sencha Touch Fastbook
- 24. Parse.com Sencha Touch 2.0
- 25. Sencha Touch密碼
- 26. 如何在Sencha Touch 2 proxy/model/store/whatever上設置CRUD方法?
- 27. Sench Touch MVC
- 28. Sencha Touch和Facebook按鈕
- 29. jqtouch/sencha touch&pdf的
- 30. Sencha Touch 2表格