2

我在 sencha touch 中定义了 store 如下:

store.js

  Ext.define('bluebutton.store.BlueButton.Testing', {
    extend: "Ext.data.Store",
    requires: [
              'bluebutton.model.BlueButton.Testing'
    ],
    config: {
        storeId: 'testingstore',
        model: 'bluebutton.model.BlueButton.Testing'
    }
});

模型.js

    Ext.define('bluebutton.model.BlueButton.Testing', {
    extend: 'Ext.data.Model',

    requires: [
             'Ext.data.proxy.LocalStorage'
    ],

    config: {
        fields: [
            { name: 'first', type: 'string' },
            { name: 'second', type: 'string' }
        ],
        proxy: {
            type: 'localstorage',
            id: '_codeAnalyzerLocalStorage'
        }
    }
});

我需要调用 getStore()

    Ext.define('bluebutton.view.BlueButton.testing', {
    extend: 'Ext.form.Panel',
    xtype: 'testing',
       requires: [

    'bluebutton.view.BlueButton.TransactionList',
    'bluebutton.view.BlueButton.MemberPopUp',
     'bluebutton.view.BlueButton.MemberDetail',
     'bluebutton.store.BlueButton.MemberList',

     'bluebutton.model.BlueButton.Testing',
     'bluebutton.store.BlueButton.Testing'




    ],

    config: {
     id:'register',
        items :[

              {
                    xtype: 'textfield',
                    name: 'name',
                    label: 'Name'
                },
                {
                    xtype: 'emailfield',
                    name: 'email',
                    label: 'Email'
                },



                {

                    xtype: 'button',
                    text: 'Test Local',
                     handler: function(button) {


                       var test =   Ext.getCmp('testingstore').getStore();   

                       alert(test);





                       }




                },









        ],


   }

});

但我得到这个错误

getStore is undefined

请帮忙。谢谢

4

3 回答 3

5

我用下面的代码试过了,它没有问题!

店铺:

Ext.define('bluebutton.store.BlueButton.Testing', {
    extend : "Ext.data.Store",
    requires : [ 'bluebutton.model.BlueButton.Testing' ],
    config : {
        storeId : 'testingstore',
        model : 'bluebutton.model.BlueButton.Testing'
    }
});

模型:

Ext.define('bluebutton.model.BlueButton.Testing', {
    extend : 'Ext.data.Model',
    requires : ['Ext.data.proxy.LocalStorage'],
    config : {
        fields : [{
                    name : 'first',
                    type : 'string'
                }, {
                    name : 'second',
                    type : 'string'
                }],
        proxy : {
            type : 'localstorage',
            id : '_codeAnalyzerLocalStorage'
        }
    }
});

看法:

Ext.define('bluebutton.view.BlueButton.Testing', {
        extend : 'Ext.form.Panel',
        xtype : 'testing',
        config : {
            fullscreen : true,
            id : 'register',
            items : [{
                        xtype : 'textfield',
                        name : 'name',
                        label : 'Name'
                    }, {
                        xtype : 'emailfield',
                        name : 'email',
                        label : 'Email'
                    }, {
                        xtype : 'button',
                        text : 'Test Local',
                        handler : function(button) {
                            var test = Ext.getStore('testingstore');
                            console.log(test);
                        }
                    }]
        }
    });

应用程序.js:

Ext.Loader.setConfig({
    enabled : true,
});

Ext.application({

    name : 'bluebutton',

    views : [ 'BlueButton.Testing', ],  
    stores : [ 'BlueButton.Testing', ], 
    models : [ 'BlueButton.Testing', ], 

    launch : function() {
        Ext.create('bluebutton.view.BlueButton.Testing');
    }

});

控制台在按下按钮后记录了我的商店。

但我认为这将是一个更好的代码,当您将按钮操作放在控制器中时,而不是视图中!

button config:
    {
        xtype : 'button',
        text : 'Test Local',
        action : 'buttonTest'

    }

控制器:

Ext.define('bluebutton.controller.BlueButton.Testing', {
    extend : 'Ext.app.Controller',
    config : {
        control : {
            'button[action="buttonTest"]' : {
                tap : 'testButtonTap'
            }
        }
    },
    testButtonTap : function() {
        var test = Ext.getStore('testingstore');
        console.log(test);
    }
});
于 2013-01-29T08:13:07.467 回答
1

你可以得到商店

var test =   Ext.getStore('testingstore');

Sencha Touch API:http ://docs.sencha.com/touch/2-1/#!/api/Ext-method-getStore

于 2013-01-25T10:00:34.530 回答
0

你必须在 app.js 中添加你的商店

你必须把你的商店放在商店数组中,因为 storeId 引用的 sencha 错误(据我所知,js 加载应用程序脚本的顺序),所以如果你想使用 storeId,请将你的商店放在 app.js 中。

分机应用程序({

name : 'bluebutton',

views : [ 'BlueButton.Testing', ],  

stores : [ 'BlueButton.Testing', ], //this is the key


models : [ 'BlueButton.Testing', ], 

launch : function() {
    Ext.create('bluebutton.view.BlueButton.Testing');
}

});

于 2015-02-15T02:10:10.940 回答