首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在sencha touch 2中存储

无法在sencha touch 2中存储
EN

Stack Overflow用户
提问于 2013-01-25 17:40:41
回答 3查看 7.7K关注 0票数 2

我在sencha touch中定义store如下:

store.js

代码语言:javascript
复制
  Ext.define('bluebutton.store.BlueButton.Testing', {
    extend: "Ext.data.Store",
    requires: [
              'bluebutton.model.BlueButton.Testing'
    ],
    config: {
        storeId: 'testingstore',
        model: 'bluebutton.model.BlueButton.Testing'
    }
});

Model.js

代码语言:javascript
复制
    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()

代码语言:javascript
复制
    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);





                       }




                },









        ],


   }

});

但是我得到了这个错误

代码语言:javascript
复制
getStore is undefined

请帮帮忙。谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-02-15 10:10:11

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

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

Ext.application({

代码语言:javascript
复制
name : 'bluebutton',

views : [ 'BlueButton.Testing', ],  

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


models : [ 'BlueButton.Testing', ], 

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

});

票数 0
EN

Stack Overflow用户

发布于 2013-01-29 16:13:07

我试着用下面的代码,它工作起来没有任何问题!

商店:

代码语言:javascript
复制
Ext.define('bluebutton.store.BlueButton.Testing', {
    extend : "Ext.data.Store",
    requires : [ 'bluebutton.model.BlueButton.Testing' ],
    config : {
        storeId : 'testingstore',
        model : 'bluebutton.model.BlueButton.Testing'
    }
});

型号:

代码语言:javascript
复制
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'
        }
    }
});

查看:

代码语言:javascript
复制
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);
                        }
                    }]
        }
    });

app.js:

代码语言:javascript
复制
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');
    }

});

按下按钮后,控制台会让我登录商店。

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

代码语言:javascript
复制
button config:
    {
        xtype : 'button',
        text : 'Test Local',
        action : 'buttonTest'

    }

控制器:

代码语言:javascript
复制
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);
    }
});
票数 5
EN

Stack Overflow用户

发布于 2013-01-25 18:00:35

你可以用以下命令获得商店:

代码语言:javascript
复制
var test =   Ext.getStore('testingstore');

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14519064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档