【问题标题】:Loading initial configuration data on extjs在 extjs 上加载初始配置数据
【发布时间】:2017-07-26 11:51:27
【问题描述】:

在以下问题上需要您的帮助。我有一个 Extjs 应用程序,我首先需要从数据库中获取一些数据,我的意思是,在加载所有内容(主要是视图)之前。这是因为我需要加载的这些数据将用于在特定视图中创建表单。 所以问题是:我应该将获取数据并将其存储在全局变量中的函数放在哪里?我试图将该函数放在 app.js 上的启动函数中,但行为很奇怪(有时会在视图呈现之前加载数据,有时会在之后加载)。

请看上面的代码:

获取数据的函数(放置在 App.js 中并在启动函数中调用):

cargarItemsEvaluacion: function()
{
    AppGlobals.itemsCargarFormEvaluacion = [];
    Ext.Ajax.request(
    {      
        url : 'app/proxy.evaluacion.php',
        method: 'GET',
        params :{
            act: 'getEvalItemsForm'

        },

        success : function(response) 
        {
            var obj = Ext.decode(response.responseText);
            Ext.each(obj.results, function(item)
            {
                //console.log(item);
                var tempItem = {
                xtype: 'container',
                layout: 'anchor',
                flex: 1,
                items: [
                {
                    //xtype: 'fieldset',
                    title: item.nombre,
                    items: [
                        {
                            id: 'item_'+item.id,
                            xtype: 'textfield',
                            fieldLabel: item.descripcion,
                            name: 'item_'+item.id,
                            allowBlank: false,
                            blankText: 'Este campo es obligatorio',
                            maskRe: /^[0-9]{1}/,
                            maxLenght: 2,
                            validateOnChange: 'true',
                            emptyText: 'Nota (1 al 10)',
                            submitEmptyText: false,
                            validator: function(value)
                            {
                                if(value.length>2 || value>10)
                                {
                                    return 'Complete con nota del 1 al 10';
                                }
                                var stringPad=/^[1-9]{1}[0-9]{0,1}/; 
                                if (!stringPad.test(value))
                                {
                                    return 'Complete con nota del 1 al 10';
                                }
                                else
                                {
                                    return true;
                                }
                            }
                        }]   
                }]
                };
                AppGlobals.itemsCargarFormEvaluacion.push(tempItem);

            });//End Ext.each

            if(AppGlobals.itemsCargarFormEvaluacion.length>0)
            {
                var itemObservacion = {
                    xtype: 'container',
                    layout: 'anchor',
                    flex: 1,
                    items: [
                    {
                        title: 'Observaciones',
                        items: [
                            /*{
                                id: 'ascenso',
                                xtype: 'checkbox',
                                boxLabel: 'Recomienda ascenso',
                                name: 'ascenso'
                            },*/
                            {
                                id: 'observaciones',
                                xtype: 'textareafield',
                                grow: true,
                                fieldLabel: 'Agregue observaciones adicionales si lo cree necesario',
                                name: 'observaciones',
                                labelAlign: 'top'
                            }
                            ]   
                    }]
                    };
                AppGlobals.itemsCargarFormEvaluacion.push(itemObservacion);
            }
        console.log(AppGlobals.itemsCargarFormEvaluacion);    
        },
        failure: function(response)
        {
            var obj = Ext.decode(response.responseText);
            console.log("Entra al failure "+response.responseText);
            //Ext.example.msg("Error", "No se pudo comprobar si es posible cargar al evaluador. Error: "+obj.error);

        }
    });//End Ext.ajax
}

这是视图上的 initComponent 函数,我需要使用从上一个函数中获得的数据生成表单:

initComponent: function(){

    var formEvaluacion = this.items[0];
    if(AppGlobals.itemsCargarFormEvaluacion.length==0)
    {
        console.log("Data still no loaded");
    }
    else
    {
        console.log("Data loaded!");    
    }
    console.log(AppGlobals.itemsCargarFormEvaluacion);
    Ext.apply(formEvaluacion,{items: AppGlobals.itemsCargarFormEvaluacion});

    this.callParent(arguments);
}  

如您所见,我检查数据是在视图呈现之前还是之后加载。有时在之前,有时在之后……我不知道它取决于什么……

我们将不胜感激。

毛罗

【问题讨论】:

    标签: extjs views launch


    【解决方案1】:

    我想我找到了解决方案。我将 cargarItemsEvaluacion 函数放入 app.js 的 init 函数中。到目前为止似乎工作正常。

    谢谢!

    【讨论】:

    • 嗨。看起来这也没有解决我的问题......有时数据不会加载。有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 2021-10-20
    • 2015-12-04
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多