iteye_165 2009-11-13 09:41
浏览 581
已采纳

表单数据提交完成后grid如何重新加载?

[code="java"]
Ext.extend(demo.module, {

init: function(){
var myPageSize=20;//grid 每頁顯示條數.常量.可以隨時更改為你需要顯示的條數.
var modelCM = new Ext.grid.ColumnModel([
{header:'模塊ID',dataIndex: 'model_id'},
{header:'模塊英文',dataIndex: 'model_en_CN'},
{header:'模塊中文',dataIndex: 'model_zh_CN'},
{header:'模塊路徑',dataIndex: 'model_path'},
{header:'模塊描述',dataIndex: 'model_description'},
{header:'模塊作者',dataIndex: 'model_author'},
{header:'創建日期',dataIndex: 'model_createdate'}
]);
modelCM.defaultSortable = false;

    var modelStore = new Ext.data.Store({
        proxy:new Ext.data.HttpProxy({url:"system/model/ModelJsonData.php"}),
        reader:new Ext.data.JsonReader({
            totalProperty:"total",
            root:"results",
            id:"model_id"},
            [{name:"model_id"},
             {name:"model_en_CN"},
             {name:"model_zh_CN"},
             {name:"model_path"},
             {name:"model_description"},
             {name:"model_author"},
             {name:"model_createdate"}]
        ),
        remoteSort: false
    });
    modelStore.setDefaultSort('model_id','desc');
    modelStore.load({params:{start:0, limit:myPageSize}});
    //查詢字段表單
    var searchData=[['productsinfo_number','產品編號'],
                               ['productsinfo_name','產品名稱'],
                               ['productstype_number','種類編號'],
                               ['productstype_name','種類名稱'],
                               ['productuse_user','使用者名稱'],
                               ['productuse_date','使用日期'],
                               ['productuse_ip','使用IP']]
    var searchStore= new Ext.data.SimpleStore({
        fields: ['value','text'],
        data: searchData
    })
    var searchCombo=new Ext.form.ComboBox({
            store:searchStore,emptyText:'請 選 擇',mode: 'local',name:'fields',
            triggerAction: 'all',valueField: 'value',displayField: 'text',width:100
        });
    /**
     * @description 查詢關鍵字 文本輸入框
     */
    var searchKey=new Ext.form.TextField({name:'keyword',emptyText:'請輸入查詢關鍵字'});

    //菜單欄
    var modelMenubar = [{
            text:'新增模塊',iconCls:'add',tooltip:'新增系統管理模塊',
            handler:doAdd,scope: this
        },'-',{
            id: 'account-edit-button',text:'修改模塊',tooltip:'编辑所选的模塊',
            iconCls:'edit',scope: this
        },'-',{
            id: 'account-delete-button',text:'删除模塊',tooltip:'删除当前选中模塊',
            iconCls:'remove',scope: this
        },'-','','','','查 询:',searchCombo,searchKey,{iconCls: 'query',scope: this}];
        //分頁導航  
        var modelPagingbar = new Ext.PagingToolbar({
            pageSize:myPageSize,
            store:modelStore,
            displayInfo: true,
            emptyMsg: "没有任何数据可以显示",
            displayMsg: '显示第{0}条到第{1}条数据,总共{2}条数据'
        });

        var modellist=new Ext.grid.GridPanel({
            id: 'list-model-panel', 
            title:'系統模塊列表',
            ds:modelStore,
            cm: modelCM,
            viewConfig: {forceFit:true},
            tbar: modelMenubar,     
            bbar: modelPagingbar,
            loadMask: {msg: '正在载入数据...'}
        });     
        this.main.add(modellist);  
        this.main.doLayout();       
 }     

});

function doAdd(){
var modelEn_CN = new Ext.form.TextField({
fieldLabel: '模塊英文名',allowBlank: false,name: 'txtModelEn_CN',anchor: '90%'
});

var modelZh_CN = new Ext.form.TextField({
fieldLabel: '模塊中文名',allowBlank: false,name: 'txtModelZh_CN',anchor: '90%'
});
var modelPath = new Ext.form.TextField({
fieldLabel: '模 塊 路 徑',allowBlank: false,name: 'txtModelPath',anchor: '90%'
});

var modelDescription = new Ext.form.TextArea({
fieldLabel: '模 塊 描 述',name: 'txtModelDescription',height: 80,anchor: '90%'
});
var modelAuthor = new Ext.form.TextField({
fieldLabel: '模 塊 作 者',allowBlank: false,name: 'txtModelAuthor',anchor: '90%'
});
var modelCreateDate = new Ext.form.DateField({
fieldLabel: '創 建 日 期',format:'Y-m-d',allowBlank: false,name: 'txtModelCreateDate',emptyText: '請選擇',anchor: '45%'
});
//创建表单开始,将表单字段导入表单组件中.确定表单提交地址.

var modelForm = new Ext.form.FormPanel({

id: 'modelForm',
baseCls: 'x-plain',labelWidth: 120,labelAlign: 'right',
url:'system/model/addModel.php',
defaultType: 'textfield',labelAlign:'right',
items: [modelEn_CN, modelZh_CN,modelPath,modelDescription,modelAuthor,modelCreateDate]

});

var win=new Ext.Window({
    title: '新增申購系統模塊',width: 550,height:320,
    layout: 'fit',bodyStyle:'padding:15px;',buttonAlign:'center',
    items: modelForm,
    buttons: [{text: '保存并關閉',
               handler: function() { 
                    if (modelForm.getForm().isValid()) {
                        modelForm.getForm().submit({                  
                            waitMsg:'请稍候',
                            waitTitle:'正在提交表单数据,请稍候。。。。。。',
                            failure: function(form, action) {
                                if(action.failureType == 'server'){ 
                                    obj = Ext.util.JSON.decode(action.response.responseText); 
                                    Ext.Msg.alert('错误信息!', obj.errors.reason); 
                                }else{ 
                                    Ext.Msg.alert('警告信息!', '认证服务器无法访问 : ' + action.response.responseText); 
                                } 
                            },
                            success: function() {
                                Ext.Msg.alert('信息', '操作成功!');
                                win.close();                                    
                                [color=red]modellist.reload();[/color]  //就是这个地方应该怎么写才正确呢?请各位帮忙看看.                                                                     
                            },                          
                            scope: this
                        });
                    } else{
                        Ext.MessageBox.alert('错误信息', '请修正错误指出.');
                    }             
               },
               scope: this},
              {text: '取消',handler: function(){win.close();},scope: this}]           
});
win.show();

}
[/code]
我的表单数据已经成功添加到数据库,但是我想添加成功后让modellist中的数据重新加载.也就是添加成功后grid马上就刷新显示出来.
[b]问题补充:[/b]
我照著你的方法改了,報[color=red]modellist is not defined[/color]這個錯誤,應該不是load的問題....是不是我的那個modellist調用不了呢?
[b]问题补充:[/b]
我把 function doAdd()放到里面去了.報:[color=red]uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://localhost/purchase/library/ext/adapter/ext/ext-base.js :: anonymous :: line 116" data: no]

Line 0[/color]這個錯誤.

  • 写回答

4条回答 默认 最新

  • 马勒格彼得 2009-11-13 10:29
    关注

    这样吧,你可以把那些变量都提取出来,做全局的,其他的不变,这样试试看 :lol:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!