I was having issues with getting a function to run after a model updateData function was called. See below for a the answer.
Page 1 / 1
Thanks to Matt and Pat for your posts on this!
http://community.skuid.com/skuid/top…
The main line of code from the below sample that provides the solution is
<br />$.when(initialUpdateOrOtherDeferredFunction()).done(eprintSuccess,doStuffAfterUpdateAttempt]).fail(lprintFailure,doStuffAfterUpdateAttempt]);
See below for the rest of the solution
<br />$ = skuid.$;<br />try{<br /> <br /> //both done and fail function take a function or array of functions as parameters. I chose an array for both to print sucess state.<br />//<a href="https://api.jquery.com/jQuery.when/" rel="nofollow" target="_blank" title="Link: https://api.jquery.com/jQuery.when/">https://api.jquery.com/jQuery.when/<br /></a>//<a href="https://api.jquery.com/deferred.done/" rel="nofollow" target="_blank" title="Link: https://api.jquery.com/deferred.done/">https://api.jquery.com/deferred.done/<br /></a>//<a href="https://api.jquery.com/deferred.fail/" rel="nofollow" target="_blank" title="Link https//apijquerycom/deferredfail/">https://api.jquery.com/deferred.fail/<br /></a>//"Since deferred.done() returns the deferred object, other methods of the deferred object can be chained to this one"<br />//this is why .fail can be appended to .done<br /> $.when(initialUpdateOrOtherDeferredFunction()).done(eprintSuccess,doStuffAfterUpdateAttempt]).fail(lprintFailure,doStuffAfterUpdateAttempt]);<br /> <br />}<br />catch(e){<br /> <br /> console.log(e);<br />}<br /><br />function initialUpdateOrOtherDeferredFunction(){<br />var mod = skuid.model.getModel('modelName');<br />//do pre-processing stuff to your model here<br />//return the deferred promise<br />return mod.updateData();<br /><br />}<br /><br /><br />function printFailure(){<br /> <br /> console.log('Failure');<br /> <br />}<br />function printSuccess(){<br /> <br /> console.log('Success');<br /> <br />}<br />function doStuffAfterUpdateAttempt(){<br />//do stuff<br />//do stuff<br />//repeat stuff <a href="https://www.youtube.com/watch?v=nt9c0UeYhFc" rel="nofollow" target="_blank">https://www.youtube.com/watch?v=nt9c0UeYhFc</a><br />}
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.