dongzhi5587 2012-06-22 16:11
浏览 66
已采纳

组合框加载速度太慢

My page loads super slow right now. Basically, i want to pre-populate the combo boxes that i have. Right now, it pre-populates each one individually and then selects the default value. This is so slow. The user will have to wait about a minute before the page is fully loaded.

I'm grabbing the values to populate the combo boxes from a server. The values to pre-select the combo box value are received in an array through the response variable. How do i speed this whole process up?

Code is below:

EXTJS

                    xtype: "combo",
                    width: 250,
                    id: "nameId",
                    name: "comboName",
                    labelStyle: 'width:100px',
                    fieldLabel:"Name",
                    allowBlank: true,
                    displayField: "nameDisplay",
                    valueField: "nameValue",
                    url: "/thelink/toGetAllComboboxValues/fromPHPFile/",



return {
    init: function (args) {

        formPanel.on({

            beforerender: function () {

                Ext.Ajax.request({
                    url: 'url/to/another/PHP/file/',
                    scope: this,
                    method: 'GET',
                    params: {
                        code_id: 'myUser',
                        number: '12345'
                    },

                    success: function (response, opts) {
                        var result = Ext.decode(response.responseText);
              Ext.getCmp('nameId').setValue(result.Name);

                    },

                });


            },

            scope: this
        });

      //add form panel here
    },

    getFormPanel: function () {

        return formPanel;
    },



    // load parameter values into the form
    loadParams: function () {

    },
    goHome: function () {

    },


};
}();

PHP TO GET COMBO BOX VALUES

//makes call to server for each individual combo box values

PHP TO GET PRE-SELECTED VALUES

//grabs all pre-selected values based on an ID and puts them in an array
  • 写回答

2条回答 默认 最新

  • dow46218 2012-06-22 18:51
    关注

    If your stores each has less than about 300 records, and there aren't really 'that' many stores on your page, what you should do is return everything from the php at once (or more preferably load all the stores with the page load itself, but it sounds like you can't do that). So, instead of your one ajax call getting the values of the selected item in the combobox, think of it more like this:

    Defined your models for each of the stores:

    Ext.define("MyModel1", {
        extend: "Ext.data.Model",
        fields: [
            {name:"field_code", type:"string"},
            {name:"field_value",      type:"string"}
        ]
    });
    

    Then define each of your stores in a very simple manner, notice that I left out the reader and proxy that you are probably currently including, for improved performance, use Ext.data.ArrayStore because it removes the necessity for each item in a record to have a named attribute (this reduces the text returned from the server and also the parsing time on the frontend):

    var myStore = Ext.create("Ext.data.ArrayStore", {
        model: "MyModel1",
        data:  []
    });
    

    Now in the ajax request that you already defined, add in the response from php all the data for the stores as attributes in the json object returned, and do them as array arrays making sure the element order matches how you defined the Ext.data.Model. The return object for my example would look something like this (the data is the array array):

    {
        my_combobox_value1: "CAD",
        my_combobox_data1: [
            ["CAD","Somthing for display of this record"],
            ["AN","Another Entry]
        ]
    }
    

    Then change the ajax request to look something like this:

    Ext.Ajax.request({
        url: 'url/to/another/PHP/file/',
        scope: this,
        method: 'GET',
        params: {
            code_id: 'myUser',
            number: '12345'
        },
    
        success: function (response, opts) {
             var result = Ext.decode(response.responseText);
             myStore.loadData(result.my_combobox_data1);
             Ext.getCmp('nameId').setValue(result.my_combobox_value1);
             ... and rinse and repeat for all stores, make sure you set the value for each combobox after the store has been loaded :)
        },
    
    });
    

    This will give you the best possible performance for you situation. If this does not work, you will have to use stores with proxies that handle everything on the server side and load data as needed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题