0
votes

I have an MVC app that I have been working on but I seem to be missing some fundamentals with namespaces and accessing objects correctly. I don't understand how to load my store when the index method is called. In my model, autoload is false and I am using the same code that I have used in other apps (non MVC) but to no avail. Any thoughts?

This is my app.js:

Ext.regApplication({
    name: 'MVC',
    defaultUrl: 'Home/index',
    launch: function(){
        console.log("Launching");
        this.viewport = new MVC.views.Viewport();

    }
});

This is my controller:

Ext.regController('Update', {

    // index action
    index: function(){
        if(networkStatus()==true){
            console.log("Checking for Updated Config: " + CONFIG_URL);
            MVC.stores.Updates.load();//Uncaught TypeError: Cannot read property 'Updates' of undefined
        }
        if ( ! this.indexView){
            this.indexView = this.render({
                xtype: 'UpdateIndex',
            });
        }
        this.application.viewport.setActiveItem(this.indexView);
    },
});

This is my Model:

Ext.regModel('UpdateModel', {
    fields: [
        {name: 'id'},
        {name: 'version'},
        {name: 'date'},
        {name: 'md5'},
        {name: 'manifest-doc'},
        {name: 'manifest-image'}
    ]
});

This is my Store:

Ext.regStore('Updates', {
    model: 'UpdateModel',
    storeId: 'Updates',
    autoLoad: false,
    proxy: {
        type: 'ajax',
        url: 'app/data/config.min.json',
        reader: new Ext.data.JsonReader({
            root: 'config',
        }),
        timeout: 6000,
        listeners: {
            exception:function () {
                console.log("Update Failed");
            }
        }
    }
});
2
Should the store be created with Ext.regStore('MVC.stores.Updates' ...? I'm pretty sure the first string to regStore is the namespace for the store you are defining. - Matt Greer
In ext.js 4 the store can be accessed via "this.getStorenameStore()", if you have defined it in the model via 'stores : ["Storename"]' - nisc
You can also try var store = Ext.StoreManager.get("Storename"); - nisc
Matt, you are correct the namespace should be the first string. I've seen people define the namespace like you did above but in the scope of the MVC tutorial I was following, I didn't see that convention. I looked at the official Sencha Touch MVC with PhoneGap tutorial and they have it defined in a similar way but not quite. I'll give it a shot... - M69

2 Answers

2
votes
0
votes

What is MVC? It should be the name of the app i.e.

    Ext.regApplication({
      name: 'MVC',