我定义了一个自定义窗体,代码如下,其中有一个dataurl属性,是自定义的,主要的功能就是传递自定义窗体要加载数据的url
- EditBranchWindow = Ext.extend(Ext.Window, {
- title : '修改',
- width : 350,
- height : 140,
- dataurl : '',
- collapsible : true,
- modal : true,
- defaults : {
- border : false
- },
- buttonAlign : 'center',
- createFormPanel : function() {
- var myproxy = new Ext.data.HttpProxy({
- url : this.dataurl,
- method : 'POST'
- })
- var myds = new Ext.data.Store({
- proxy : myproxy,
- reader : new Ext.data.JsonReader({
- root : 'users',
- totalProperty : 'total',
- successProperty : 'success',
- id : 'id'
- }, [{
- name : 'name',
- mapping : 'name'
- }, {
- name : 'email',
- mapping : 'email'
- }, {
- name : 'id',
- mapping : 'id'
- }])
- });
- /*
- * var sstore = new Ext.data.SimpleStore({ proxy:proxy });
- */
- myds.load();
- var mcombo = new Ext.form.ComboBox({
- store : myds,
- displayField : 'name',
- emptyText : '请选择一个用户...',
- // valueField : 'id',
- fieldLabel : '支部管理员',
- id : 'master.id',
- name : 'master.id'
- });
- var editpanel = new Ext.form.FormPanel({
- bodyStyle : 'padding-top:6px',
- defaultType : 'textfield',
- labelAlign : 'right',
- labelWidth : 100,
- labelPad : 0,
- frame : true,
- defaults : {
- allowBlank : false,
- width : 158
- },
- items : [{
- name : 'branch.title',
- fieldLabel : '支部名称',
- blankText : '支部名称不能为空'
- }, mcombo]
- });
- return editpanel;
- },
- subdata : function() {
- if (this.fp.form.isValid()) {
- this.fp.form.submit({
- waitMsg : '正在提交数据...',
- url : 'saveBranch.action',
- success : function(form, action) {
- window.location.reload();
- },
- failure : function(form, action) {
- form.reset();
- Ext.MessageBox.show({
- title : '警告',
- msg : '发生错误!',
- buttons : Ext.MessageBox.OK,
- icon : Ext.MessageBox.ERROR
- });
- }
- });
- } else {
- Ext.MessageBox.alert('提示', '请填写完整');
- }
- },
- initComponent : function() {
- EditBranchWindow.superclass.initComponent.call(this);
- this.fp = this.createFormPanel();
- this.add(this.fp);
- this.addButton('提交', this.subdata, this);
- this.addButton('重置', function() {
- this.fp.form.reset();
- }, this);
- }
- });
在工具栏的按钮单击事件以后加载数据,代码如下:
- var newButtonclick = function() {
- var win = new EditBranchWindow({
- title : '添加',
- dataurl : 'new.action'
- });
- win.show();
- };
- var mcombo = new Ext.form.ComboBox({
- typeAhead: true,
- store : myds,
- displayField : 'name',
- emptyText : '请选择一个用户...',
- valueField : 'id',
- fieldLabel : '支部管理员',
- id : 'master.id',
- name : 'master.id',
- mode:'local'
- });
多了一个mode:'local'就好了,后来在ff里面运行的时候,发现在combo里面输入4个字符,列表就能显示出来,原来combo默认会从远程取数据