1

我正在尝试将我的配置页面保存在本地存储中并稍后检索它。我不太确定该怎么做。当我尝试使用“store.load”加载商店但它说加载未定义。

我的配置页面代码是

var flag = 1;
var count = 3;
var apptitle;
Ext.define("InfoImage.view.Settings",{
                    extend : 'Ext.form.Panel',
                    requires : [
                    //'InfoImage.view.workItemPanel',
                    'Ext.TitleBar', 'Ext.field.Text', 'Ext.field.Toggle',
                            'Ext.field.Select', 'Ext.layout.HBox',
                            'Ext.field.Number', 'Ext.field.Checkbox',
                            'Ext.form.FieldSet', 'Ext.field.Password',
                            'Ext.field.Url' ],
                    xtype : 'settingsPanel',
                    id : 'settings',
                    config : {
                        //store:'configStore',
                        scrollable : {
                            direction : 'vertical'
                        },
                        items : [
                                {
                                    xtype : 'toolbar',
                                    ui : 'dark',
                                    docked : 'top',
                                    id:'myTitle',
                                    title : 'InfoImage Settings',
                                    items : [
                                    {
                                        xtype : 'button',
                                        iconCls : 'home',
                                        iconMask : true,
                                        ui : 'normal',
                                        id : 'homeSettingbtn'
                                    },

                                    {xtype: 'spacer'},
                                    {
                                        xtype : 'button',
                                        //text:'Save',
                                        iconCls : 'save_fin',
                                        iconMask : true,
                                        ui : 'normal',
                                        id : 'savebtn',
                                        handler : function() {
                                        }
                                    }, 
                                    {
                                        xtype : 'button',
                                        //text:'Default',
                                        iconCls : 'default',
                                        iconMask : true,
                                        ui : 'normal',
                                        handler : function() {
                                            var form = Ext.getCmp('settings');
                                            form.reset();
                                        }

                                    }

                                    ]
                                },

                                {
                                    //fieldset defined for the Server Configuration details to be entered.
                                    xtype : 'fieldset',
                                    title : 'Server Configuration',
                                    defaults : {
                                        xtype : 'selectfield',
                                        labelWidth : '30%',
                                    },
                                    items : [
                                            {
                                                xtype : 'urlfield',
                                                name : 'servname',
                                                id : 'servname',
                                                label : 'Server Name',
                                                labelWidth : '30%'
                                            },
                                            {
                                                xtype : 'numberfield',
                                                id : 'port',
                                                name : 'port',
                                                label : 'Port',
                                                value : '80',
                                                labelWidth : '30%'
                                            },
                                            {
                                                xtype : 'selectfield',
                                                name : 'protocol',
                                                id : 'protocol',
                                                label : 'Protocol',
                                                labelWidth : '30%',
                                                usePicker : false,
                                                //ui:'action',
                                                //styleHtmlContent:true,
                                                //visible:true,
                                                //fieldStyle:'background-color:#FFF;',
                                                handler : function() {
                                                },
                                                options : [ {
                                                    text : 'HTTP',
                                                    value : 'HTTP'
                                                }, {
                                                    text : 'HTTPS',
                                                    value : 'HTTPS'
                                                }

                                                ]
                                            }

                                    ]
                                },
                                {
                                    //fieldset defined for the User Configuration details to be entered.
                                    xtype : 'fieldset',
                                    title : 'User Configuration',
                                    items : [ {
                                        xtype : 'textfield',
                                        name : 'username',
                                        id : 'username',
                                        label : 'User Name',
                                        labelWidth : '30%'
                                    }, {
                                        xtype : 'passwordfield',
                                        name : 'password',
                                        id : 'password',
                                        label : 'Password',
                                        labelWidth : '30%'
                                    }, {
                                        xtype : 'textfield',
                                        id : 'domain',
                                        name : 'domain',
                                        label : 'Domain',
                                        labelWidth : '30%'
                                    } ]
                                },



                                {
                                    //fieldset defined for the App Subtitle to be entered.
                                    xtype : 'fieldset',
                                    items : [ {
                                        xtype : 'textfield',
                                        name : 'apptitle',
                                        id : 'apptitle',
                                        label : 'App Subtitle',
                                        labelWidth : '30%',
                                        value : 'Mobile Client Work Manager'
                                    } ]
                                }

                        ]

                    }
                });

我的controller.js中的代码是

Ext.getCmp('settings').getStore().load();

我应该做什么将这些数据存储在本地存储中并检索它?

4

1 回答 1

0

我认为问题出在这里:

//store:'configStore',

也许你应该取消注释它。

从 localStorage 读取数据:

Ext.getCmp('settings').getStore().load();

将数据写入本地存储:

Ext.getCmp('settings').getStore().add(data);
Ext.getCmp('settings').getStore().sync();

sync() 方法用于将 Sencha Storage 与 HTML5 localStorage 同步(如果我做对了 - 它对我有用)

于 2012-07-26T14:36:10.207 回答