0
我在JSP中使用Ext JS组合框。第一次加载页面时,combox框不显示。 我在我的Firebug控制台中看到一个错误,关联商店没有定义。 (TypeError: cpStore is undefined)
Ext JS Combobox第一次不加载
但是,我注意到下一个请求正常工作。
请建议我可以做些什么来避免这个问题。
function displayCPBox(idPrefix){
var cpSelectList = Ext.create ('Ext.data.JsonStore', {
storeId: idPrefix+'cpSelectStore',
remoteSort: true,
autoLoad: true,
proxy: {
type: 'ajax',
url: proyecto + 'extjs/data/cpData.jsp',
reader: {
type: 'json',
root: 'data',
idProperty: 'id'
}
},
fields: [
{name:'id', type: 'float'},
{name:'codigo', type: 'string'}
]
});
var multiCombo = Ext.create('Ext.form.field.ComboBox', {
fieldLabel: 'CP',
renderTo: idPrefix+'cpSelectCombo',
id: idPrefix + 'cpSelectComboBox',
displayField: 'codigo',
valueField : 'id',
width: 200,
labelWidth: 50,
store: cpSelectList,
queryMode: 'remote',
minChars: 1,
cls : 'cp-margin',
listeners :{
select: function(combo, records, eOpts){
getZipInfoForCodigoFormFields(records,document.getElementById(idPrefix+'localidad') ,document.getElementById(idPrefix+'provincia'),document.getElementById(idPrefix+'pais'),doc ument.getElementById(idPrefix+'zona'));
}
}
});
}
代码加载过程中设置的值:
var cpStore = Ext.data.StoreManager.lookup('<%=idPrefix%>'+'cpSelectStore');
cpStore.on('load',function() {
<%
Long zipCodeForDisplayLong = oportunidad.getId_lib_cp();
long zipCodeForDisplay = (zipCodeForDisplayLong == null) ? -1 : zipCodeForDisplayLong.longValue();
%>
var selectedzipCodeValue= <%=zipCodeForDisplay %>;
if(selectedzipCodeValue != -1)
{
var selectedCPVal = cpStore.findRecord("id",selectedzipCodeValue);
Ext.getCmp('<%=idPrefix%>'+'cpSelectComboBox').setValue(selectedCPVal.get("id"));
}
});
cpStore.load();
我重写了我的代码,设置加载的值,它现在工作正常。非常感谢。 – user2478960