我的页面加载速度超慢。基本上,我想预先填充我拥有的组合框。现在,它会单独预填充每个,然后选择默认值。这太慢了。用户必须等待大约一分钟才能完全加载页面。
我正在获取值以从服务器填充组合框。要预先选择组合框值的值通过响应变量在数组中接收。如何加快整个过程?
代码如下:
分机分
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
//makes call to server for each individual combo box values
PHP 获取预选值
//grabs all pre-selected values based on an ID and puts them in an array
如果你的商店每个都有不到 300 条记录,并且你的页面上并没有真正"那么"的商店,你应该做的是一次从 php 返回所有内容(或者更优选加载所有商店与页面加载本身,但听起来你不能这样做)。 因此,与其通过一个 ajax 调用来获取组合框中选定项的值,不如这样考虑:
为每个商店定义模型:
Ext.define("MyModel1", {
extend: "Ext.data.Model",
fields: [
{name:"field_code", type:"string"},
{name:"field_value", type:"string"}
]
});
然后以非常简单的方式定义每个存储,请注意,我省略了您当前可能包含的读取器和代理,为了提高性能,请使用 Ext.data.ArrayStore,因为它消除了记录中每个项目都具有命名属性的必要性(这减少了从服务器返回的文本以及前端的解析时间):
var myStore = Ext.create("Ext.data.ArrayStore", {
model: "MyModel1",
data: []
});
现在,在你已经定义的 ajax 请求中,在 php 的响应中添加存储的所有数据作为返回的 json 对象中的属性,并将它们作为数组数组执行,以确保元素顺序与你定义 Ext.data.Model 的方式匹配。 我示例的返回对象如下所示(数据是数组数组):
{
my_combobox_value1: "CAD",
my_combobox_data1: [
["CAD","Somthing for display of this record"],
["AN","Another Entry]
]
}
然后将 ajax 请求更改为如下所示:
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 :)
},
});
这将为您提供适合您情况的最佳性能。 如果这不起作用,您将不得不使用带有代理的存储,这些代理处理服务器端的所有内容并根据需要加载数据。
首先,我建议在用户需要之前不要检索每个组合的完整值列表(更改值或单击触发器时)。 您可以通过为您的组合提供一个商店来做到这一点,该商店设置了您的 URL 代理。
为了节省初始单值显示,一种选择是将字符串值以及 id 存储在您的记录中(或者可能不存储它,但无论如何都会将其发送到客户端)。 但是,这不是很好,并且在摆脱完整列表请求后加载时间可能足够快。 如果不是,请尝试查看是否可以请求一个请求中显示的所有单个值。