PDA

View Full Version : Unable to use setTitle method when using a string concatenated with datastore data



d1984
14 Sep 2011, 6:32 AM
I have the following code attached as a handler to a button:


myapp.stores.vehicleInfo.load();
myapp.toolbars.vehicleInfoToolbar.setTitle('Image 1 of ');


Which within my defined namespace loads the store and then sets the title of a toolbar - this works.
This code doesn't work:


myapp.stores.vehicleInfo.load();
myapp.toolbars.vehicleInfoToolbar.setTitle('Image 1 of'+ myapp.stores.vehicleInfo.data.items[0].data.imageTotal);

giving the error: 'cannot read property of "data" of undefined'
But when I click the button a second time, it sets the title of the toolbar as expected e.g. Image 1 of 10.
What is going on here? How do I solve this? I tried using the settimeout method in case the setTitle method was being called too early before the store was finished loading. However this failed to solve the problem.
Many thanks.

steve1964
14 Sep 2011, 2:38 PM
Hi myapp.stores.vehicleInfo.load(); is an async process, at the time you use:
myapp.toolbars.vehicleInfoToolbar.setTitle('Image 1 of'+myapp.stores.vehicleInfo.data.items[0].data.imageTotal);
the store is not loaded yet, you have to fire the load event of the store and use setTtle in this function

d1984
15 Sep 2011, 12:03 AM
Thanks that is the right answer. =D>