【问题标题】:Sencha Touch MVC load storeSencha Touch MVC 加载存储
【发布时间】:2012-01-15 04:43:59
【问题描述】:

我有一个我一直在开发的 MVC 应用程序,但我似乎缺少一些关于命名空间和正确访问对象的基础知识。我不明白在调用 index 方法时如何加载我的商店。在我的模型中,自动加载是错误的,我使用的代码与在其他应用程序(非 MVC)中使用的代码相同,但无济于事。有什么想法吗?

这是我的 app.js:

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

    }
});

这是我的控制器:

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);
    },
});

这是我的模特:

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

这是我的商店:

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");
            }
        }
    }
});

【问题讨论】:

  • 商店应该用Ext.regStore('MVC.stores.Updates' ...创建吗?我很确定regStore 的第一个字符串是您正在定义的商店的命名空间。
  • 在 ext.js 4 中,如果您在模型中通过 'stores : ["Storename"]' 定义了商店,则可以通过 "this.getStorenameStore()" 访问商店
  • 你也可以试试 var store = Ext.StoreManager.get("Storename");
  • 马特,你说得对,命名空间应该是第一个字符串。我见过人们像上面那样定义命名空间,但在我遵循的 MVC 教程的范围内,我没有看到这种约定。我查看了官方的 Sencha Touch MVC with PhoneGap 教程,他们以类似的方式定义了它,但并不完全。我会试一试...

标签: sencha-touch


【解决方案1】:

试试

var updatesStore = Ext.getStore("Updates");

http://docs.sencha.com/touch/2-0/#!/api/Ext-method-getStore

【讨论】:

  • 我也会试试这个,但我注意到你在我使用 1.1.1 时引用了 2.0 文档
  • 所以,我可以使用这个来获得对商店的引用,太棒了!问题,我正在使用以下内容尝试访问它。我想我这样做对吗?更新商店.load(); updatesStore.each(function(record){ console.log(record); }
【解决方案2】:

MVC 是什么?它应该是应用程序的名称,即

    Ext.regApplication({
      name: 'MVC',

【讨论】:

  • 在这种情况下,MVC 是我的应用程序的命名空间。我一直在创建一个模板以供继续使用。
猜你喜欢
  • 2012-07-24
  • 1970-01-01
  • 1970-01-01
  • 2012-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-18
相关资源
最近更新 更多