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.
Thanks.
the store load() method is asynchronous and it usualy takes a while to load the store so … you should set the title on the callback function when you are certain you have the data