我在做一个下拉列表的级联
1
2
3
4
5
6
7
|
Ext.getCmp(
'_s_combobox_peSite_siteName'
).on(
'change'
,
function
(e,select){
//为下一级下拉框加载新值
//参数说明:select:peSite.Id url:需加载的下接框 target:数据存放位置
//自定义方法getList(select,url,target)
//alert('e:' +e + ' select: ' + select);
getList(select,
'/entity/teaching/electiveManage_ajaxGetTraining.action?siteId='
+select,
'_s_combobox_peTraining_trainingName'
,
'学期'
);
});
|
1
2
3
4
5
6
7
8
9
10
11
12
|
function
getList(id,url,target,title){
Ext.Ajax.request({
url:url,
method:
'GET'
,
disableCaching:
true
,
callback:
function
(option,success,response){
if
(success){
_s_combobox_peTraining_trainingName = eval(response.responseText);
}
}
});
}
|
因为从服务单传过来response.responseText的内容就是下面所示的一个拼接字符串
1
|
_s_combobox_peTraining_trainingName =
new
Ext.form.ComboBox({ applyTo:
'_s_combobox_peTraining_trainingName'
, width:
150
, store:
new
Ext.data.SimpleStore({ fields: [
'id'
,
'name'
], data : [[
'4af8dec33e9d07a7013e9d0a57bc0004'
,
'2013第一学期'
],[
'4af8dec33e9d07a7013e9d0b5fbc0005'
,
'2013第二学期'
]] }), valueField:
'id'
, displayField:
'name'
, selectOnFocus:
true
, allowBlank:
true
, typeAhead:
false
, fieldLabel:
'学期'
, name:
'_s_combobox_peTraining_trainingName'
, id:
'_s_combobox_peTraining_trainingName'
, triggerAction:
'all'
, editable:
true
, mode:
'local'
, emptyText:
''
, blankText:
''
});
|
如果直接写成:_s_combobox_peTraining_trainingName =response.responseText
浏览器会把response.responseText当前一个字符串来处理,这样页面就无法显示,
可以通过js里面的alert(typeof(response.responseText))方法来查看它的类型(String),但是这里我要的是一个对象,所在我用js里面的eval(response.responseText)方法将它转换成了object类型,alert(typeof(response.responseText))弹出来的是object类型,这样页面就能显示了
产明
1
2
3
|
这里主要说明两点:
1、通过js里面的eval(String)方法将字符串转换成object对象
2、通过为同一个object对象重新赋值来改变他原来的参数值
|
本文转自 wbb827 51CTO博客,原文链接:http://blog.51cto.com/wbb827/1201871