EXT 二级联动下拉列表

page.html代码如下

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
  2.   
  3. <html>  
  4.   
  5. <head>  
  6.   
  7.   <title>省份与城市联动的例子</title>  
  8.   
  9.     <meta http-equiv="content-type" content="text/html; charset=utf-8">  
  10.   
  11.   <link rel="stylesheet" type="text/css" href="../../../resources/css/ext-all.css">  
  12.   
  13.      
  14.   
  15.   <script type="text/javascript" src="../../../adapter/ext/ext-base.js"></script>  
  16.   
  17.   <script type="text/javascript" src="../../../ext-all.js"></script>  
  18.   
  19.   <script type="text/javascript" src="../../../ext-lang-zh_CN.js"></script>  
  20.   
  21.   <script type="text/javascript" src="city.js"></script>  
  22.   
  23.   <script>  
  24.   
  25. Ext.onReady(function(){   
  26.   
  27.   
  28.   
  29.     重载Grid的排序 applySort   
  30.   
  31.     Ext.data.Store.prototype.applySort = function(){ //重载 applySort   
  32.   
  33.         if(this.sortInfo && !this.remoteSort){   
  34.   
  35.             var s = this.sortInfo, f = s.field;   
  36.   
  37.             var st = this.fields.get(f).sortType;   
  38.   
  39.             var fn = function(r1, r2){   
  40.   
  41.               var v1 = st(r1.data[f]), v2 = st(r2.data[f]);   
  42.   
  43.                 // 添加:修复汉字排序异常的Bug   
  44.   
  45.                if(typeof(v1) == "string"){ //若为字符串,   
  46.   
  47.                  return v1.localeCompare(v2);//则用 localeCompare 比较汉字字符串, Firefox 与 IE 均支持   
  48.   
  49.                }   
  50.   
  51.               return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);   
  52.   
  53.             };   
  54.   
  55.             this.data.sort(s.direction, fn);   
  56.   
  57.             if(this.snapshot && this.snapshot != this.data){   
  58.   
  59.                 this.snapshot.sort(s.direction, fn);   
  60.   
  61.             }   
  62.   
  63.         }   
  64.   
  65.     };   
  66.   
  67.   
  68.   
  69.        
  70.   
  71.     var provinceComBo=new Ext.form.ComboBox({   
  72.   
  73.         hiddenName:'province',   
  74.   
  75.         name: 'province_name',   
  76.   
  77.         valueField:"province",   
  78.   
  79.         displayField:"province",   
  80.   
  81.         mode:'local',   
  82.   
  83.         fieldLabel: '所在省份',   
  84.   
  85.         blankText:'请选择省份',   
  86.   
  87.         emptyText:'请选择省份',   
  88.   
  89.         editable:false,   
  90.   
  91.         anchor:'90%',   
  92.   
  93.         forceSelection:true,   
  94.   
  95.         triggerAction:'all',   
  96.   
  97.         store:new Ext.data.SimpleStore(   
  98.   
  99.             {   
  100.   
  101.                 fields: ["province","city"],   
  102.   
  103.                 data:citys,   
  104.   
  105.                 sortInfo:{field:'province'}   
  106.   
  107.             }   
  108.   
  109.         ),   
  110.   
  111.         listeners:{   
  112.   
  113.             select:function(combo, record, index){   
  114.   
  115.             /*select : ( Ext.form.ComboBox combo, Ext.data.Record record, Number index )   
  116.   
  117.             Fires when a list item is selected   
  118.   
  119.             Listeners will be called with the following arguments:   
  120.   
  121.                
  122.   
  123.                 * combo : Ext.form.ComboBox   
  124.   
  125.                   This combo box   
  126.   
  127.                 * record : Ext.data.Record   
  128.   
  129.                   The data record returned from the underlying store   
  130.   
  131.                 * index : Number   
  132.   
  133.                   The index of the selected item in the dropdown list   
  134.   
  135.                
  136.   
  137.             */   
  138.   
  139.                 cityCombo.clearValue();   
  140.   
  141.                 cityCombo.store.loadData(record.data.city);   
  142.   
  143.             }   
  144.   
  145.         },   
  146.   
  147.         applyTo: 'provinceComBo'   
  148.   
  149.     })   
  150.   
  151.   
  152.   
  153.     var cityCombo=new Ext.form.ComboBox({   
  154.   
  155.         hiddenName:'city',   
  156.   
  157.         name:'city_name',   
  158.   
  159.         valueField:"city",   
  160.   
  161.         displayField:"city",   
  162.   
  163.         mode:'local',   
  164.   
  165.         fieldLabel: '所在城市',   
  166.   
  167.         blankText:'请选择城市',   
  168.   
  169.         emptyText:'请选择城市',    
  170.   
  171.         editable:false,   
  172.   
  173.         anchor:'90%',   
  174.   
  175.         forceSelection:true,   
  176.   
  177.         triggerAction:'all',   
  178.   
  179.         store:new Ext.data.SimpleStore({fields: ["city"],data:[],sortInfo:{field:'city'}}),   
  180.   
  181.         applyTo: 'cityCombo'   
  182.   
  183.     });   
  184.   
  185.        
  186.   
  187. })   
  188.   
  189.   
  190.   
  191.   </script>  
  192.   
  193. </head>  
  194.   
  195. <body>  
  196.   
  197. <input type="text" id="provinceComBo" size="20"/><input type="text" id="cityCombo" size="20"/>  
  198.   
  199. </body>  
  200.   
  201. </html>  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

  <title>省份与城市联动的例子</title>

	<meta http-equiv="content-type" content="text/html; charset=utf-8">

  <link rel="stylesheet" type="text/css" href="../../../resources/css/ext-all.css">

  

  <script type="text/javascript" src="../../../adapter/ext/ext-base.js"></script>

  <script type="text/javascript" src="../../../ext-all.js"></script>

  <script type="text/javascript" src="../../../ext-lang-zh_CN.js"></script>

  <script type="text/javascript" src="city.js"></script>

  <script>

Ext.onReady(function(){



	重载Grid的排序 applySort

	Ext.data.Store.prototype.applySort = function(){ //重载 applySort

		if(this.sortInfo && !this.remoteSort){

			var s = this.sortInfo, f = s.field;

			var st = this.fields.get(f).sortType;

			var fn = function(r1, r2){

			  var v1 = st(r1.data[f]), v2 = st(r2.data[f]);

				// 添加:修复汉字排序异常的Bug

			   if(typeof(v1) == "string"){ //若为字符串,

				 return v1.localeCompare(v2);//则用 localeCompare 比较汉字字符串, Firefox 与 IE 均支持

			   }

			  return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);

			};

			this.data.sort(s.direction, fn);

			if(this.snapshot && this.snapshot != this.data){

				this.snapshot.sort(s.direction, fn);

			}

		}

	};



	

	var provinceComBo=new Ext.form.ComboBox({

		hiddenName:'province',

		name: 'province_name',

		valueField:"province",

		displayField:"province",

		mode:'local',

		fieldLabel: '所在省份',

		blankText:'请选择省份',

		emptyText:'请选择省份',

		editable:false,

		anchor:'90%',

		forceSelection:true,

		triggerAction:'all',

		store:new Ext.data.SimpleStore(

			{

				fields: ["province","city"],

				data:citys,

				sortInfo:{field:'province'}

			}

		),

		listeners:{

			select:function(combo, record, index){

			/*select : ( Ext.form.ComboBox combo, Ext.data.Record record, Number index )

			Fires when a list item is selected

			Listeners will be called with the following arguments:

			

				* combo : Ext.form.ComboBox

				  This combo box

				* record : Ext.data.Record

				  The data record returned from the underlying store

				* index : Number

				  The index of the selected item in the dropdown list

			

			*/

				cityCombo.clearValue();

				cityCombo.store.loadData(record.data.city);

			}

		},

        applyTo: 'provinceComBo'

	})



	var cityCombo=new Ext.form.ComboBox({

		hiddenName:'city',

		name:'city_name',

		valueField:"city",

		displayField:"city",

		mode:'local',

		fieldLabel: '所在城市',

		blankText:'请选择城市',

		emptyText:'请选择城市', 

		editable:false,

		anchor:'90%',

		forceSelection:true,

		triggerAction:'all',

		store:new Ext.data.SimpleStore({fields: ["city"],data:[],sortInfo:{field:'city'}}),

        applyTo: 'cityCombo'

	});

	

})



  </script>

</head>

<body>

<input type="text" id="provinceComBo" size="20"/><input type="text" id="cityCombo" size="20"/>

</body>

</html>
 
  1. city.js的代码  
city.js的代码
 
  1. <PRE class=jscript name="code">var citys=[   
  2.   
  3. ['北京',[['北京'],['通县'],['昌平'],['大兴'],['密云'],['延庆'], ['顺义'],['怀柔'],['平谷'],['石景山'],['朝阳'],['西城'],['东城'],['丰台'],['宣武'],['崇文'], ['海淀']]],   
  4.   
  5. ['上海',[['上海县'],['嘉定'],['松江'],['南汇'],['奉贤'],['川沙'],['青浦'],['崇明'],['金山']]],   
  6.   
  7. ['天津',[['蓟县'],['宝坻'],['武清'],['静海'],['宁河']]]]</PRE> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会尝试回答你的问题。以下是一个 ExtJS4.2 实例,包含一个表格和一个带有联动下拉列表的列: ```javascript Ext.require([ 'Ext.grid.*', 'Ext.data.*', 'Ext.form.*' ]); Ext.onReady(function() { // 创建一个简单的数据存储 var store = Ext.create('Ext.data.Store', { fields: ['name', 'email', 'phone', 'department'], data: [ { 'name': 'Lisa', "email":"lisa@simpsons.com", "phone":"555-111-1224", "department": "Sales" }, { 'name': 'Bart', "email":"bart@simpsons.com", "phone":"555-222-1234", "department": "Marketing" }, { 'name': 'Homer', "email":"homer@simpsons.com", "phone":"555-222-1244", "department": "Engineering" }, { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254", "department": "Support" } ] }); // 创建一个下拉框的存储 var departmentStore = Ext.create('Ext.data.Store', { fields: ['name'], data : [ { "name": "Sales" }, { "name": "Marketing" }, { "name": "Engineering" }, { "name": "Support" } ] }); // 创建一个表格 var grid = Ext.create('Ext.grid.Panel', { renderTo: Ext.getBody(), store: store, height: 250, width: 500, title: 'Employee Directory', columns: [ { header: 'Name', dataIndex: 'name' }, { header: 'Email', dataIndex: 'email', flex: 1 }, { header: 'Phone', dataIndex: 'phone' }, // 创建一个带有联动下拉列表的列 { header: 'Department', dataIndex: 'department', editor: { xtype: 'combobox', store: departmentStore, displayField: 'name', valueField: 'name', editable: false, forceSelection: true } } ], // 启用编辑功能 plugins: [ Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1 }) ] }); }); ``` 这个例子中,我们创建了一个名为 `grid` 的表格,包含四个列:姓名、电子邮件、电话和部门。其中,部门列是一个带有联动下拉列表的列,该下拉列表的数据存储在 `departmentStore` 中。我们使用 `Ext.grid.plugin.CellEditing` 插件启用了编辑功能,从而允许用户编辑表格中的数据。 希望这个例子对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值