0

I am in the app.js file. there is a function that gets executed when user logs in to the stytem successfully;

loginSuccess: function() {

this.getViewport().getLayout().setActiveItem(1).store.load();   // Calls the Store of the i need to navigate 
        this.getViewport().getLayout().setActiveItem(1);  // The view i will be navigating

}

I am getting an error stating this.getViewport().getLayout().setActiveItem(1).store is undefined. i think i'm calling the Store the wrong way. how could i correct this ? How can i call the Store from the app.js ?

UPDATE

var st = Ext.getStore('myStore');
        st.load();
        st.on('load', function() { 
            this.getViewport().getLayout().setActiveItem(1);  


        });
sha
  • 17,824
  • 5
  • 63
  • 98
Sharon Watinsan
  • 9,620
  • 31
  • 96
  • 140

1 Answers1

2

Correct way to initiate store loading is:

var st = Ext.getStore('MyStore');
st.load();

just remember that loading is async process, so if you want something to be executed after store is loaded you can't just write a code after load() - you would need to subscribe to the load event.

sha
  • 17,824
  • 5
  • 63
  • 98
  • What do you mean by subscribe to the `load` method ? – Sharon Watinsan Jul 05 '12 at 14:40
  • `st.on('load', function() { got_something_her });` – sha Jul 05 '12 at 14:42
  • Do you mean to write `this.getViewport().getLayout().setActiveItem(1); ` inside the `st.on('load',function() .....` ? – Sharon Watinsan Jul 05 '12 at 14:51
  • This is to display the 2nd view when login is successful. Before i show this 2nd view, i am Loading the records from the Store, and then displaying the view which would show those records. – Sharon Watinsan Jul 05 '12 at 17:01
  • then yes, in that event handler function do you setActive – sha Jul 05 '12 at 17:07
  • I have updated my Post with the code, but i get an error `this.getViewport is not a function` . Could you help me ? – Sharon Watinsan Jul 05 '12 at 17:39
  • You have scope issue. Handler is not being called in the same scope original function was. Add one more `this` parameter when subscribing to the event. And I recommend very strongly to walk-through Sencha MVC application guide. You will feel yourself much more comfortable with the framework. – sha Jul 05 '12 at 17:43
  • You mean `this.this.getViewport().getLayout().setActiveItem(1);` ? – Sharon Watinsan Jul 05 '12 at 18:29
  • No, i mean add parameter to `on` function: st.on('load', function() {}, this) - check out documentation http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Element-method-on – sha Jul 05 '12 at 18:38