我定义了一个变量type,在下拉框选项的值改变时给type赋值,然后去动态的选择Store,加载数据,可在select事件中是动态的赋值了,但Store加载的始终是默认的那个,求高手解决
var type = '搜产品';
// 产品数据模型
var ds_cp = new Ext.data.Store({
url : 'findCpByName.action',
reader : new Ext.data.JsonReader({
root : 'root',
totalProperty : 'totalProperty'
}, [{
name : 'cpInfoId',
mapping : 'cpInfoId',
type : 'int'
}, {
name : 'qyRegId',
mapping : 'qyRegId',
type : 'int'
}, {
name : 'cpMc',
mapping : 'cpMc',
type : 'string'
}, {
name : 'cpMs',
mapping : 'cpMs',
type : 'string'
}, {
name : 'cpTime',
mapping : 'cpTime',
type : 'date',
format : 'Y-m-d H:i:s'
}])
});
// 快照数据模型
var kz_ds = new Ext.data.Store({
url : 'findAllkz.action',
reader : new Ext.data.JsonReader({
root : 'root',
totalProperty : 'totalProperty'
}, [{
name : 'photoId',
mapping : 'photoId',
type : 'int'
}, {
name : 'qyRegName',
mapping : 'qyRegName',
type : 'string'
}, {
name : 'photoTitle',
mapping : 'photoTitle',
type : 'string'
}, {
name : 'photoDesc',
mapping : 'photoDesc',
type : 'string'
}, {
name : 'photoTime',
mapping : 'photoTime',
type : 'date',
format : 'Y-m-d H:i:s'
}])
})
// Custom rendering Template for the View
var resultTpl = new Ext.XTemplate(
'<tpl for=".">',
'<div class="search-item">',
'<h3><span>{cpTime}<br /> {qyRegId}</span>',
'<a href="http://192.168.9.101:8080/erciso/information.action?cpInfoId={cpInfoId}®InfoId={qyRegId}" target="_blank">{cpMc}</a></h3>',
'<p>{cpMs}</p>', '</div></tpl>');// Custom rendering Template for the View
var resultTpl_kz = new Ext.XTemplate(
'<tpl for=".">',
'<div class="search-item">',
'<h3><span>{photoTime}<br /> {qyRegId}</span>',
'<a href="http://extjs.com/forum/showthread.php?t={cpInfoId}" target="_blank">{photoTitle}</a></h3>',
'<p>{photoDesc}</p>', '</div></tpl>');var text = new Ext.form.TextField({
width : 300,
height : 50,
enableKeyEvents : true,
listeners : {
'keypress' : function(field, e) {
var b = combo.getValue();
var mc = field.getValue();
if (null != mc || "" != mc) {
if (b == '搜产品') {
ds_cp.load({
params : {
cpmc : mc,
start : 0,
limit : 10
}
});
} if (b == '搜快照') {
kz_ds.load({
params : {
kzmc : mc,
start : 0,
limit : 10
}
})
}
}
}
}
});var combo = new Ext.form.ComboBox({
fieldLabel : '搜索类型',
name : 'searchtype',
mode : 'local',
editable : false,
value : '搜产品',
triggerAction : 'all',
displayField : 'searchtype',
valueField : 'searchtype',
store : new Ext.data.SimpleStore({
fields : ['searchtype'],
data : [['搜产品'], ['搜快照']]
}),
listeners : {
'select' : function(com, record, index) {
type = com.getValue();
mc = text.getValue();
if (type == '搜产品') {
Ext.getCmp('dv').refresh();
ds_cp.load({
params : {
cpmc : mc,
start : 0,
limit : 10
}
});
} if (type == '搜快照') {
Ext.getCmp('dv').refresh();
kz_ds.load({
params : {
kzmc : mc,
start : 0,
limit : 10
}
})
} }
}
})
var panel = new Ext.Panel({
title : '搜索',
iconCls : 'icon-search',
height : 480,
autoScroll : true,
items : new Ext.DataView({
id : 'dv',
tpl : type == '搜产品' ? resultTpl : resultTpl_kz,
loadMask : {
msg : '数据加载中...'
},
multiSelect : true,
overClass : 'x-view-over',
store : ds_cp,
itemSelector : 'div.search-item'
}), tbar : ['Search: ', ' ', text, '-', combo], bbar : new Ext.PagingToolbar({
store : type == '搜产品' ? ds_cp : kz_ds,
pageSize : 10,
displayInfo : true,
displayMsg : '第 {0} - {1} 条 共 {2} 条',
emptyMsg : "没有找到相关信息"
})
});var search = {
id : 'sousuo',
border : false,
layout : 'border',
items : [panel]
}
var type = '搜产品';
// 产品数据模型
var ds_cp = new Ext.data.Store({
url : 'findCpByName.action',
reader : new Ext.data.JsonReader({
root : 'root',
totalProperty : 'totalProperty'
}, [{
name : 'cpInfoId',
mapping : 'cpInfoId',
type : 'int'
}, {
name : 'qyRegId',
mapping : 'qyRegId',
type : 'int'
}, {
name : 'cpMc',
mapping : 'cpMc',
type : 'string'
}, {
name : 'cpMs',
mapping : 'cpMs',
type : 'string'
}, {
name : 'cpTime',
mapping : 'cpTime',
type : 'date',
format : 'Y-m-d H:i:s'
}])
});
// 快照数据模型
var kz_ds = new Ext.data.Store({
url : 'findAllkz.action',
reader : new Ext.data.JsonReader({
root : 'root',
totalProperty : 'totalProperty'
}, [{
name : 'photoId',
mapping : 'photoId',
type : 'int'
}, {
name : 'qyRegName',
mapping : 'qyRegName',
type : 'string'
}, {
name : 'photoTitle',
mapping : 'photoTitle',
type : 'string'
}, {
name : 'photoDesc',
mapping : 'photoDesc',
type : 'string'
}, {
name : 'photoTime',
mapping : 'photoTime',
type : 'date',
format : 'Y-m-d H:i:s'
}])
})
// Custom rendering Template for the View
var resultTpl = new Ext.XTemplate(
'<tpl for=".">',
'<div class="search-item">',
'<h3><span>{cpTime}<br /> {qyRegId}</span>',
'<a href="http://192.168.9.101:8080/erciso/information.action?cpInfoId={cpInfoId}®InfoId={qyRegId}" target="_blank">{cpMc}</a></h3>',
'<p>{cpMs}</p>', '</div></tpl>');// Custom rendering Template for the View
var resultTpl_kz = new Ext.XTemplate(
'<tpl for=".">',
'<div class="search-item">',
'<h3><span>{photoTime}<br /> {qyRegId}</span>',
'<a href="http://extjs.com/forum/showthread.php?t={cpInfoId}" target="_blank">{photoTitle}</a></h3>',
'<p>{photoDesc}</p>', '</div></tpl>');var text = new Ext.form.TextField({
width : 300,
height : 50,
enableKeyEvents : true,
listeners : {
'keypress' : function(field, e) {
var b = combo.getValue();
var mc = field.getValue();
if (null != mc || "" != mc) {
if (b == '搜产品') {
ds_cp.load({
params : {
cpmc : mc,
start : 0,
limit : 10
}
});
} if (b == '搜快照') {
kz_ds.load({
params : {
kzmc : mc,
start : 0,
limit : 10
}
})
}
}
}
}
});var combo = new Ext.form.ComboBox({
fieldLabel : '搜索类型',
name : 'searchtype',
mode : 'local',
editable : false,
value : '搜产品',
triggerAction : 'all',
displayField : 'searchtype',
valueField : 'searchtype',
store : new Ext.data.SimpleStore({
fields : ['searchtype'],
data : [['搜产品'], ['搜快照']]
}),
listeners : {
'select' : function(com, record, index) {
type = com.getValue();
mc = text.getValue();
if (type == '搜产品') {
Ext.getCmp('dv').refresh();
ds_cp.load({
params : {
cpmc : mc,
start : 0,
limit : 10
}
});
} if (type == '搜快照') {
Ext.getCmp('dv').refresh();
kz_ds.load({
params : {
kzmc : mc,
start : 0,
limit : 10
}
})
} }
}
})
var panel = new Ext.Panel({
title : '搜索',
iconCls : 'icon-search',
height : 480,
autoScroll : true,
items : new Ext.DataView({
id : 'dv',
tpl : type == '搜产品' ? resultTpl : resultTpl_kz,
loadMask : {
msg : '数据加载中...'
},
multiSelect : true,
overClass : 'x-view-over',
store : ds_cp,
itemSelector : 'div.search-item'
}), tbar : ['Search: ', ' ', text, '-', combo], bbar : new Ext.PagingToolbar({
store : type == '搜产品' ? ds_cp : kz_ds,
pageSize : 10,
displayInfo : true,
displayMsg : '第 {0} - {1} 条 共 {2} 条',
emptyMsg : "没有找到相关信息"
})
});var search = {
id : 'sousuo',
border : false,
layout : 'border',
items : [panel]
}
fieldLabel : '搜索类型',
name : 'searchtype',
mode : 'local',
editable : false,
value : '搜产品',
triggerAction : 'all',
displayField : 'searchtype',
valueField : 'searchtype',
store : new Ext.data.SimpleStore({
fields : ['searchtype'],
data : [['搜产品'], ['搜快照']]
}),
listeners : {
'select' : function(com, record, index) {
type = com.getValue();
mc = text.getValue();//mc是全局的了
if (type == '搜产品') {
Ext.getCmp('dv').refresh();
ds_cp.load({
params : {
cpmc : mc,
start : 0,
limit : 10
}
});
} if (type == '搜快照') {
Ext.getCmp('dv').refresh();
kz_ds.load({
params : {
kzmc : mc,
start : 0,
limit : 10
}
})
} }
}
})
var text = new Ext.form.TextField({
width : 300,
height : 50,
enableKeyEvents : true,
listeners : {
'keypress' : function(field, e) {
var b = combo.getValue();
var mc = field.getValue(); // mc局部的了
if (null != mc || "" != mc) {
if (b == '搜产品') {
ds_cp.load({
params : {
cpmc : mc,
start : 0,
limit : 10
}
});
} if (b == '搜快照') {
kz_ds.load({
params : {
kzmc : mc,
start : 0,
limit : 10
}
})
}
}
}
}
});
然后看一下后台是否返回了正确的数据。
title : '搜索',
iconCls : 'icon-search',
height : 480,
autoScroll : true,
items : new Ext.DataView({
id : 'dv',
tpl : type == '搜产品' ? resultTpl : resultTpl_kz,
loadMask : {
msg : '数据加载中...'
},
multiSelect : true,
overClass : 'x-view-over',
store : ds_cp,//这个也要跟着type改变吧???
itemSelector : 'div.search-item'
}),
params : {
cpmc : mc,
start : 0,
limit : 10
}
});
这个提交过去有没有数据返回?