如何爲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. YQL in sencha touch MVC
- 3. Sencha touch 2 MVC商店
- 4. Sencha Touch MVC最佳實踐
- 5. Sencha Touch查詢
- 6. Sencha touch 2.製作MVC網格
- 7. Sencha Touch i18n
- 8. Sencha Touch JSONPReader
- 9. Sencha Touch XML
- 10. getStore(); undefined Sencha Touch 2
- 11. 定義新的xtype字段sencha touch MVC
- 12. Sencha Touch 2 MVC列表事件接線
- 13. Sencha Touch。 Ext.getStore()函數
- 14. Sencha Touch XML列表
- 15. 總價值Sencha Touch
- 16. Sencha Touch 2 vs DHTMLX Touch
- 17. 鏈接http://cdn.sencha.com/touch/sencha-touch-2.2.1/sencha-touch-all.js不工作
- 18. Sencha Touch Mocking
- 19. sencha touch messagebox unclickable
- 20. Sencha Touch + DeftJS
- 21. sencha-touch using ActionSheet
- 22. Sencha Touch密碼
- 23. Sencha Touch入門
- 24. Sencha Touch 2 TypeError
- 25. Sencha Touch Fastbook
- 26. Ext.Ajax.request Sencha Touch
- 27. sencha touch getView()?
- 28. Sencha Touch + SharePoint
- 29. Sencha Touch 2 HtmlEditor
- 30. sencha touch Ext.Router