现在的位置: 首页 > 综合 > 正文

EXT自定义窗体加载数据

2013年07月29日 ⁄ 综合 ⁄ 共 5863字 ⁄ 字号 评论关闭
我定义了一个自定义窗体,代码如下,其中有一个dataurl属性,是自定义的,主要的功能就是传递自定义窗体要加载数据的url
Js代码 复制代码
  1. EditBranchWindow = Ext.extend(Ext.Window, {  
  2.         title : '修改',  
  3.         width : 350,  
  4.         height : 140,  
  5.         dataurl : '',  
  6.         collapsible : true,  
  7.         modal : true,  
  8.         defaults : {  
  9.             border : false  
  10.         },  
  11.         buttonAlign : 'center',  
  12.         createFormPanel : function() {  
  13.             var myproxy = new Ext.data.HttpProxy({  
  14.                 url : this.dataurl,  
  15.                 method : 'POST'  
  16.             })  
  17.             var myds = new Ext.data.Store({  
  18.                 proxy : myproxy,  
  19.                 reader : new Ext.data.JsonReader({  
  20.                     root : 'users',  
  21.                     totalProperty : 'total',  
  22.                     successProperty : 'success',  
  23.                     id : 'id'  
  24.                 }, [{  
  25.                     name : 'name',  
  26.                     mapping : 'name'  
  27.                 }, {  
  28.                     name : 'email',  
  29.                     mapping : 'email'  
  30.                 }, {  
  31.                     name : 'id',  
  32.                     mapping : 'id'  
  33.                 }])  
  34.             });  
  35.             /* 
  36.              * var sstore = new Ext.data.SimpleStore({ proxy:proxy }); 
  37.              */  
  38.             myds.load();  
  39.             var mcombo = new Ext.form.ComboBox({  
  40.                 store : myds,  
  41.                 displayField : 'name',  
  42.                 emptyText : '请选择一个用户...',  
  43.                 // valueField : 'id',  
  44.                 fieldLabel : '支部管理员',  
  45.                 id : 'master.id',  
  46.                 name : 'master.id'  
  47.             });  
  48.   
  49.             var editpanel = new Ext.form.FormPanel({  
  50.                 bodyStyle : 'padding-top:6px',  
  51.                 defaultType : 'textfield',  
  52.                 labelAlign : 'right',  
  53.                 labelWidth : 100,  
  54.                 labelPad : 0,  
  55.                 frame : true,  
  56.                 defaults : {  
  57.                     allowBlank : false,  
  58.                     width : 158  
  59.                 },  
  60.                 items : [{  
  61.                     name : 'branch.title',  
  62.                     fieldLabel : '支部名称',  
  63.                     blankText : '支部名称不能为空'  
  64.                 }, mcombo]  
  65.             });  
  66.             return editpanel;  
  67.         },  
  68.         subdata : function() {  
  69.             if (this.fp.form.isValid()) {  
  70.                 this.fp.form.submit({  
  71.                     waitMsg : '正在提交数据...',  
  72.                     url : 'saveBranch.action',  
  73.                     success : function(form, action) {  
  74.                         window.location.reload();  
  75.                     },  
  76.                     failure : function(form, action) {  
  77.                         form.reset();  
  78.                         Ext.MessageBox.show({  
  79.                             title : '警告',  
  80.                             msg : '发生错误!',  
  81.                             buttons : Ext.MessageBox.OK,  
  82.                             icon : Ext.MessageBox.ERROR  
  83.                         });  
  84.                     }  
  85.                 });  
  86.             } else {  
  87.                 Ext.MessageBox.alert('提示''请填写完整');  
  88.             }  
  89.         },  
  90.         initComponent : function() {  
  91.             EditBranchWindow.superclass.initComponent.call(this);  
  92.             this.fp = this.createFormPanel();  
  93.             this.add(this.fp);  
  94.             this.addButton('提交'this.subdata, this);  
  95.             this.addButton('重置'function() {  
  96.                 this.fp.form.reset();  
  97.             }, this);  
  98.         }  
  99.     });  

在工具栏的按钮单击事件以后加载数据,代码如下:

Js代码 复制代码
  1. var newButtonclick = function() {  
  2.         var win = new EditBranchWindow({  
  3.             title : '添加',  
  4.             dataurl : 'new.action'  
  5.         });  
  6.         win.show();  
  7.     }; 

Js代码 复制代码
  1. var mcombo = new Ext.form.ComboBox({  
  2.             typeAhead: true,  
  3.             store : myds,  
  4.             displayField : 'name',  
  5.             emptyText : '请选择一个用户...',  
  6.             valueField : 'id',  
  7.             fieldLabel : '支部管理员',  
  8.             id : 'master.id',  
  9.             name : 'master.id',  
  10.             mode:'local'  
  11.         });  

多了一个mode:'local'就好了,后来在ff里面运行的时候,发现在combo里面输入4个字符,列表就能显示出来,原来combo默认会从远程取数据

抱歉!评论已关闭.