How do I call a beforeSave method (i.e. a method that is triggered every time a model record is added, updated and/or saved) for a Sencha Touch MVC Model?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(assuming Sencha Touch 1.x)
As far as I know there is no event that tells you that the data WILL be changed but hasn’t changed yet.
However, the post-change event is called ‘datachanged’. If you just need to know that your data is changed (and not BEFORE it is changed), add a listener for this ‘datachanged’ event and discard the rest that I have written.
However, if you really need a ‘beforedatachanged’ event, read on:
You could implement your own event(and call it ‘beforedatachanged’) by using Ext.override to override the Sencha behavior and trigger your new event before the data is actually changed.
It might sound difficult, but it really is not:
First check this out:
http://docs.sencha.com/touch/1-1/source/AbstractStore.html
Go and find “onBatchComplete”, you’ll see that it fires the ‘datachanged’ event:
Before the “this.suspendEvents();” you have to fire your own custom event, because after that, the operations are executed.
To override this, write something like this in your application:
Then you need to listen to the beforedatachanged event in your model code and you’re all set.