extjs combox动态添加
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<!--ExtJs框架开始-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../locale/ext-lang-zh_CN.js" type="text/javascript"></script><!--中文翻译js-->
<script type="text/javascript" src="../ext.js"></script>
<script type="text/javascript" src="../ext-all.js"></script>
<script type="text/javascript" src="./jquery-1.8.3.js"></script>
<link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css" />
<!--ExtJs框架结束-->
<script type="text/javascript">
Ext.require(‘Ext.*‘);
Ext.onReady(function(){
//1.实体M
Ext.define(‘State‘,{
extend : ‘Ext.data.Model‘,
fields : [
{type:‘int‘,name:‘id‘},
{type:‘string‘,name:‘cname‘}
]
});
//内存中的数据D
<?php
$language = array(array());
?>
var localData1;
localData1 = <?php echo json_encode($language);?>;
//2.定义store,这里区分是内存中的还是远程服务器的
//2.1 内存中的
var localStore = Ext.create(‘Ext.data.Store‘,{
model:State,
data : localData1
});
//定义radioGroup
var raidos = Ext.create(‘Ext.form.RadioGroup‘,{
itemId:‘raidos‘,
id :‘raidos‘,
width:200,
name :‘raidos‘,
fieldLabel: ‘选择进行改变‘,
columns: 2,
vertical: true,
items: [
{ boxLabel: ‘列表1‘, name: ‘rb‘, inputValue: ‘1‘,checked: true},
{ boxLabel: ‘列表2‘, name: ‘rb‘, inputValue: ‘2‘,listeners:{change:onChangeRadio} }
]
});
//定义combo
var localCombo = Ext.create(‘Ext.form.field.ComboBox‘,{
itemId:‘local-combo‘,
id :‘local-combo‘,
name :‘local-combo‘,
fieldLabel :‘请选择省‘,
displayField:‘cname‘,
valueField:‘id‘,
store:localStore,
queryMode:‘local‘,
forceSelection: true,
allowBlank:false,
editable: true,
emptyText:‘请选择省‘,
blankText : ‘请选择省‘
});
//定义显示的容器
var dataPanel = Ext.create(‘Ext.panel.Panel‘,{
renderTo : document.body,
width : 400,
height :300,
title : ‘Combo box 的简单使用,这里分别用基于内存和基于服务器的实现‘,
plain :true,
margin:‘30 10 0 80‘,
bodyStyle: "padding: 45px 15px 15px 15px;",
defaults :{
autoScroll: true,
bodyPadding: 10
},
items:[
raidos,
localCombo
]
});
//事件监听
function onChangeRadio(field,value,oldValue){
if(value){
localCombo.store.removeAt(4);
}else{
localCombo.store.insert(4,[{‘id‘:5,‘cname‘:‘青海省‘}]);
}
}
var n = 0;
$(‘#test‘).click(function(){
$.post("city.php",function(result){
var obj = eval(result);
$(obj).each(function(index) {
var val = obj[index];
// alert(val.id + " " + val.cname);
localCombo.store.insert(n++,[{‘id‘:val.id,‘cname‘:val.cname}]);
});
});
})
});
</script>
</head>
<body>
<div id="test">aaaaaaaaaa</div>
</body>
</html>