Results 1 to 4 of 4

Thread: Store is missing from viewModel

  1. #1
    Sencha Premium Member
    Join Date
    Sep 2015
    Posts
    6

    Default Answered: Store is missing from viewModel

    I'm having an issue where (in the viewController initViewModel method) this.getViewModel().getStore('storeName') returns null, even though the store is defined. The store in question is a chained store, and its source store has already loaded.

    I have an example of this in this fiddle: https://fiddle.sencha.com/#fiddle/10gk

    In the fiddle, the main viewModel has a groups store and an items store. After the groups store loads, it creates a panel for each group and adds it to the main view. This panel (of my own type) has a viewModel which has a chained store referencing the items store in the main model.

    in the initViewModel method of this viewController, it attempts to call getViewModel().getStore("items"), but the method returns null. There does not appear to be any valid reason for this. The result of this is that the groupName that should be shown at the top of the panel (via a binding) is not shown.

    Main Question:
    Is this a defect, or am I missing something? If I'm missing something, how do I correctly access the store?

    Edit: You can see the error being thrown in the console: "[W] XTemplate evaluation exception: Cannot read property 'on' of null"

  2. Hi,

    The initViewModel method can be used to run things after the view model is created, however it does not guarantee that the stores in a few model are setup and available. You may wish to add your events to the store itself, guaranteeing that they will run when the store is created. Adding the listeners in the initViewModel method is really not the appropriate place to do that.

    Also note that as you are using a chained store, the load event for the parent store may already be fired before the chain is created thus adding a load event to the chained store may be too late in the process.

    Regards,

    Kevin
    Sencha Support Team

  3. #2
    Sencha - Support Team keckeroo's Avatar
    Join Date
    Mar 2008
    Location
    Winnipeg, Canada
    Posts
    387
    Answers
    12

    Default

    Hi,

    The initViewModel method can be used to run things after the view model is created, however it does not guarantee that the stores in a few model are setup and available. You may wish to add your events to the store itself, guaranteeing that they will run when the store is created. Adding the listeners in the initViewModel method is really not the appropriate place to do that.

    Also note that as you are using a chained store, the load event for the parent store may already be fired before the chain is created thus adding a load event to the chained store may be too late in the process.

    Regards,

    Kevin
    Sencha Support Team

  4. #3
    Sencha Premium Member
    Join Date
    Sep 2015
    Posts
    6

    Default

    Thanks for the reply.

    Quote Originally Posted by keckeroo View Post
    You may wish to add your events to the store itself, guaranteeing that they will run when the store is created. Adding the listeners in the initViewModel method is really not the appropriate place to do that.
    I understand that I can add listeners to the config of the store, but how do I connect the event handlers with methods in the viewController?

  5. #4
    Sencha Premium Member
    Join Date
    Sep 2015
    Posts
    6

    Default

    Hmm... according to this thread, it looks like it might not be possible without using a hack: https://www.sencha.com/forum/showthr...30#post1120430

    I would like to believe that's not the case, though. Seems like some pretty straightforward functionality.

Similar Threads

  1. Ext files missing for ViewModel binding
    By mysticav in forum Ext 5: Q&A
    Replies: 3
    Last Post: 30 May 2015, 8:34 PM
  2. Replies: 2
    Last Post: 20 Feb 2015, 3:05 AM
  3. Replies: 1
    Last Post: 6 Oct 2014, 7:07 AM
  4. Replies: 1
    Last Post: 6 Oct 2014, 7:07 AM
  5. Replies: 2
    Last Post: 24 Jul 2014, 1:50 AM

Tags for this Thread

Posting Permissions

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