How to use callback functions in Appcelerator’s Titanium

Interested in a hands-on tutorial in Titanium? Building Cross-Platform Apps using Titanium, Alloy, and Appcelerator Cloud Services

As part of our internal “Crash Course To Titanium”, I was teaching our guys how to use a Common JS module to pull data from a remote server and generate data for a tableview.  The problem came when we’d finished generating the data, we had to pass it back to the View.  The hacky solution would be to store the TableView object in a Global variable that can be accessed anywhere.  Of course, that’s not the best solution, a much better one is to use a callback function passed as a parameter to the CommonJS function which is then called when the tableviewdata has been prepared.

Here’s a simplified version of how we got it working:

Thanks to Ricardo for pointing us in the right direction:

Anyone interested in Titanium development should check out our tutorials and also join


About Phil Smithson

Ultrarunner & CTO. Passions include Mobile app development, Scrum, Kanban, Wordpress and Symfony.

Leave a Reply

Your email address will not be published. Required fields are marked *