我在 JSP 中使用 Ext JS 组合框。第一次加载页面时,没有显示组合框。我在 Firebug 控制台中看到未定义关联存储的错误。(TypeError: cpStore is undefined)
但是,我注意到下一个请求可以正常工作。
请建议我可以做些什么来避免这个问题。
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();