Results 1 to 3 of 3

Thread: Unable to use setTitle method when using a string concatenated with datastore data

  1. #1
    Touch Premium Member
    Join Date
    Sep 2011
    Posts
    33
    Vote Rating
    0
      0  

    Default Unable to use setTitle method when using a string concatenated with datastore data

    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.

  2. #2
    Sencha User
    Join Date
    Aug 2010
    Posts
    314
    Vote Rating
    5
      0  

    Default

    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

  3. #3
    Touch Premium Member
    Join Date
    Sep 2011
    Posts
    33
    Vote Rating
    0
      0  

    Default

    Thanks that is the right answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •