Ext.onReady(function() {
var allParameters;
var states = Ext.create('Ext.data.Store', {
fields: ['abbreviation', 'name'],
data: [{
name: 'ALABAMA',
abbreviation: 'AL'
}, {
name: 'ALASKA',
abbreviation: 'AK'
}, {
name: 'AMERICAN SAMOA',
abbreviation: 'AS'
}, {
name: 'ARIZONA',
abbreviation: 'AZ'
}, {
name: 'ARKANSAS',
abbreviation: 'AR'
}, {
name: 'CALIFORNIA',
abbreviation: 'CA'
}, {
name: 'COLORADO',
abbreviation: 'CO'
}, {
name: 'CONNECTICUT',
abbreviation: 'CT'
}, {
name: 'DELAWARE',
abbreviation: 'DE'
}, {
name: 'DISTRICT OF COLUMBIA',
abbreviation: 'DC'
}, {
name: 'FEDERATED STATES OF MICRONESIA',
abbreviation: 'FM'
}, {
name: 'FLORIDA',
abbreviation: 'FL'
}, {
name: 'GEORGIA',
abbreviation: 'GA'
}, {
name: 'GUAM',
abbreviation: 'GU'
}, {
name: 'HAWAII',
abbreviation: 'HI'
}, {
name: 'IDAHO',
abbreviation: 'ID'
}, {
name: 'ILLINOIS',
abbreviation: 'IL'
}, {
name: 'INDIANA',
abbreviation: 'IN'
}, {
name: 'IOWA',
abbreviation: 'IA'
}, {
name: 'KANSAS',
abbreviation: 'KS'
}, {
name: 'KENTUCKY',
abbreviation: 'KY'
}, {
name: 'LOUISIANA',
abbreviation: 'LA'
}, {
name: 'MAINE',
abbreviation: 'ME'
}, {
name: 'MARSHALL ISLANDS',
abbreviation: 'MH'
}, {
name: 'MARYLAND',
abbreviation: 'MD'
}, {
name: 'MASSACHUSETTS',
abbreviation: 'MA'
}, {
name: 'MICHIGAN',
abbreviation: 'MI'
}, {
name: 'MINNESOTA',
abbreviation: 'MN'
}, {
name: 'MISSISSIPPI',
abbreviation: 'MS'
}, {
name: 'MISSOURI',
abbreviation: 'MO'
}, {
name: 'MONTANA',
abbreviation: 'MT'
}, {
name: 'NEBRASKA',
abbreviation: 'NE'
}, {
name: 'NEVADA',
abbreviation: 'NV'
}, {
name: 'NEW HAMPSHIRE',
abbreviation: 'NH'
}, {
name: 'NEW JERSEY',
abbreviation: 'NJ'
}, {
name: 'NEW MEXICO',
abbreviation: 'NM'
}, {
name: 'NEW YORK',
abbreviation: 'NY'
}, {
name: 'NORTH CAROLINA',
abbreviation: 'NC'
}, {
name: 'NORTH DAKOTA',
abbreviation: 'ND'
}, {
name: 'NORTHERN MARIANA ISLANDS',
abbreviation: 'MP'
}, {
name: 'OHIO',
abbreviation: 'OH'
}, {
name: 'OKLAHOMA',
abbreviation: 'OK'
}, {
name: 'OREGON',
abbreviation: 'OR'
}, {
name: 'PALAU',
abbreviation: 'PW'
}, {
name: 'PENNSYLVANIA',
abbreviation: 'PA'
}, {
name: 'PUERTO RICO',
abbreviation: 'PR'
}, {
name: 'RHODE ISLAND',
abbreviation: 'RI'
}, {
name: 'SOUTH CAROLINA',
abbreviation: 'SC'
}, {
name: 'SOUTH DAKOTA',
abbreviation: 'SD'
}, {
name: 'TENNESSEE',
abbreviation: 'TN'
}, {
name: 'TEXAS',
abbreviation: 'TX'
}, {
name: 'UTAH',
abbreviation: 'UT'
}, {
name: 'VERMONT',
abbreviation: 'VT'
}, {
name: 'VIRGIN ISLANDS',
abbreviation: 'VI'
}, {
name: 'VIRGINIA',
abbreviation: 'VA'
}, {
name: 'WASHINGTON',
abbreviation: 'WA'
}, {
name: 'WEST VIRGINIA',
abbreviation: 'WV'
}, {
name: 'WISCONSIN',
abbreviation: 'WI'
}, {
name: 'WYOMING',
abbreviation: 'WY'
}]
});
function myFunction()
{
// add the variables here.
}
var simple = Ext.create('Ext.form.Panel', {
frame: true,
title: 'Please select your certifications',
bodyStyle: 'padding:5px',
width: 350,
layout: 'form',
style: 'margin:0 auto;margin-top:100px;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);-webkit-box-shadow: 0 0 8px rgba(0, 0, 0, 0.5)',
shadow: 'true',
items: [{
xtype: 'combo',
fieldlabel: 'Location',
width: 120,
emptyText: 'Select One',
store: states,
displayField: 'name',
valueField: 'abbreviation',
tpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'<div class="x-boundlist-item">{abbreviation} - {name}</div>',
'</tpl>'
),
displayTpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'{abbreviation} - {name}',
'</tpl>'
),
multiSelect: true,
listeners: {
'select': 'myFunction()'
}
}],
buttons: [{
text: 'Submit',
formBind: true,
handler: function(btn, evt) {
simple.getForm().submit({
url: 'http://localhost:8080/****/****',
params: {data: 'data'}
});
}
}]
});
simple.render(document.body);
});每当选择记录时,我都希望将其添加到变量allParameters中。有人能帮忙吗。提前谢谢。
发布于 2013-11-22 09:10:56
我为此做了很多尝试和错误,但这个问题的答案其实很简单。ExtJS本身返回变量"list.value“中选择的所有记录的值。
请参阅以下代码:
var simple = Ext.create('Ext.form.Panel', {
frame: true,
title: 'Please select your certifications',
bodyStyle: 'padding:5px',
width: 350,
layout: 'form',
style: 'margin:0 auto;margin-top:100px;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);-webkit-box-shadow: 0 0 8px rgba(0, 0, 0, 0.5)',
shadow: 'true',
items: [{
xtype: 'combo',
fieldlabel: 'Location',
width: 120,
emptyText: 'Select One',
store: states,
displayField: 'name',
valueField: 'abbreviation',
tpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'<div class="x-boundlist-item">{abbreviation} - {name}</div>',
'</tpl>'
),
displayTpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'{abbreviation} - {name}',
'</tpl>'
),
multiSelect: true,
listeners: {
select: function(list) {
allParameters = (list.value).toString();
alert(allParameters);
}
}
}],
buttons: [{
text: 'Submit',
formBind: true,
handler: function(btn, evt) {
simple.getForm().submit({
url: 'http://localhost:8080/****/****',
params: {data: allParameters}
});
}
}]
});上述代码中的变量allParameters存储所有选定记录的值。
https://stackoverflow.com/questions/20140361
复制相似问题