Jackie Chan
Jackie Chan

Reputation: 2662

Object #<Object> has no method 'getStore' on the app init

I'm trying to get Store in the view on the init of the applicatoin, however the console tells me: Object #<Object> has no method 'getStore'

I'm wondering how would you get a store in this sequence:

  1. Initialise app
  2. Get user GPS location
  3. Create a store
  4. Display view with the store
    init: function () { 
        this.callParent();
        console.log("controller init");
    },
    launch: function () {
        this.getApplicationSettings();
        this.getApplicationRegionalisation();
        Ext.getStore("appSettings").setValue("region", "Melbourne");

        var store = Ext.create("APN.store.Locations");
        var geo = Ext.create('Ext.util.Geolocation', {
            autoUpdate: false,
            listeners: {
                locationupdate: function(geo) {
                    var location = store.getClosestLocation(geo.getLatitude(), geo.getLongitude());
                    Ext.getStore("appSettings").setValue("region", location.get("location"));
                },
                locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
                }
            }
        });

And then in the view I would like to call something like this, correct me if I'm doing a stupid thing:

    requires: [
        'APN.store.AppSettings'
    ],
..... omitted stuff

// in items:
        items: [
            {
                itemId: 'nav_home',
        id: 'homeView',
                group: '',
                title: "Home",
                layout: 'vbox',
                slideButton: { selector: 'toolbar' },
                settingsButton: { selector: 'toolbar' },
                items: [{
                   xtype: 'articlelist',
                   id: 'latestNews',
                   category: 'Latest',
                   feedUrlName: 
// here is the place where it bugs out!
Ext.getStore("appSettings").getValue(Ext.getStore("appSettings").getValue("region").get("menuItems").home.url,
               }
                ],
            },


Upvotes: 0

Views: 722

Answers (1)

ThinkFloyd
ThinkFloyd

Reputation: 5021

Wherever you are creating the view, you can create the store before that and set store to the view explicitly so that when initialize function is executed it will get this.config.store. To get GPS location on app initialization, you can get location in Launch function of Ext.application before even creating the store and view. If you want to create view only after store data is loaded, you should create view in load callback of store.

I hope this is what you were looking for, if not please add some code to your question so that we can comment on specifics.

Upvotes: 1

Related Questions