Sencha和localStorage

时间:2013-08-06 07:40:54

标签: variables extjs local-storage

早上好,

我是Sencha的新手。我的login.js中有以下代码,它从删除服务器上的JSON文档中检索表单字段。它根据数据创建一个数组,我需要使用它来填充表单:

var url = 'http://domainxxx.net/';
loginFields = new Array();
Ext.onReady(function(){var theform = Ext.Ajax.request({
                                    url: url+'login',
                                    type: 'get',
                                    scope: this,
                                    dataType: "JSON",
                                    success: function(response){

                                        formFields = new Array();

                                        var numFields = Ext.JSON.decode(response.responseText).length;
                                        for (var inf=0;inf<numFields;inf++){
                                            afield = new Array();
                                            afield['xtype'] = 'textfield';
                                            afield['name'] = Ext.JSON.decode(response.responseText)[inf].Name;
                                            afield['itemId'] = Ext.JSON.decode(response.responseText)[inf].Name;
                                            afield['required'] = true;
                                            afield['description'] = Ext.JSON.decode(response.responseText)[inf].Description;
                                            afield['placeHolder'] = Ext.JSON.decode(response.responseText)[inf].Description;
                                            afield['maxlength'] = Ext.JSON.decode(response.responseText)[inf].Length;
                                            if(Ext.JSON.decode(response.responseText)[inf].Type == 1){afield['xtype']= 'passwordfield';}
                                            if(Ext.JSON.decode(response.responseText)[inf].Type == 0){afield['xtype']= 'emailfield';}
                                            loginFields.push(afield);    
                                        }

                                        console.log(loginFields);

                                    }
                                })
});

然后问题是使用此变量填充表单。我尝试将它放在表单配置中,如下所示,但没有运气。我也尝试过使用localStorage,但这也不起作用。

Ext.define('axis3.view.Login', {
extend: 'Ext.form.Panel',
alias: "widget.loginview",
requires: ['Ext.form.FieldSet', 'Ext.form.Password', 'Ext.Label', 'Ext.Img'],  config: {
    title: 'Login',
    itemId: 'loginform',

    items: [
                {
                    xtype: 'image',
                    src: Ext.Viewport.getOrientation() == 'portrait' ? 'images/logo.png' : 'images/logo.png',
                    style: Ext.Viewport.getOrientation() == 'portrait' ? 'width:271px;height:93px;margin:2em auto' : 'width:271px;height:93px;margin:2em auto'
                },
                {
                    xtype: 'label',
                    html: 'Login failed. Please enter the correct credentials.',
                    itemId: 'signInFailedLabel',
                    hidden: true,
                    hideAnimation: 'fadeOut',
                    showAnimation: 'fadeIn',
                    style: 'color:#990000;margin:5px 0px;'
                },
                {
                    xtype: 'fieldset',
                    title: 'Login',
                    items: [

    FORM VARIABLES IN HERE

                    ]
                },
                {
                    xtype: 'button',
                    itemId: 'logInButton',
                    ui: 'action',
                    padding: '10px',
                    text: 'Log In'
                }
    ],
    listeners: [{............

欢迎任何建议

1 个答案:

答案 0 :(得分:1)

您使用的是Array而不是Object。而不是说var aField = new Array(),而是说var aField = new Object()

请注意,简而言之,您也可以这样做而不是使用构造函数:

var myArray = [];
car myObject = {};