ExtJs使用心得

  1. 关于Ext.Ajax.request

    Ext.Ajax.request可以通过定义success和failure属性来判断是否成功,并取出返回值,获取返回值的方法如下:(此方法 Ext.data.HttpProxy同样有效)

  •     先定义success和failure属性
  •     通过Ext.util.JSON.decode(response.responseText)来获取Json格式的数据

 

Ext.Ajax.request
Ext.Ajax.request({
                        url : 
'url',
                        params : {
                            ID : record.data.ID
                        },
                        success : 
function(response, options) {
                            
var txt=Ext.util.JSON.decode(response.responseText); 
                            
                            
if(txt.success)
                            {
                                Ext.Msg.show({
                                    title : 
'成功提示',
                                    msg : 
'删除成功!',
                                    buttons : Ext.Msg.OK,
                                    icon: Ext.MessageBox.INFO
                                });
                                Project_grid.getStore().remove(record);
                            }
                            
else
                            {
                                Ext.Msg.show({
                                    title : 
'错误提示',
                                    msg : txt.msg,
                                    buttons : Ext.Msg.OK,
                                    icon : Ext.Msg.ERROR
                                });
                            }
                        },
                        failure : 
function() {
                            Ext.Msg.show({
                                title : 
'错误提示',
                                msg : 
'删除时发生错误!',
                                buttons : Ext.Msg.OK,
                                icon : Ext.Msg.ERROR
                            });
                        }
                    });

 

2、关于 Ext.FormPanel

    可以通过FormPanel.form.submit来提交到服务器,然后再通过传回来的值来处理接下来的工作。

form.submit
//提交到服务器
                            PformPanel.form.submit
                            (
                                {
                                    url:url,  
//提交的页面路径
                                    method:'post',//提交方式为post
                                    //提交成功的回调函数
                                    success:function(form,action)
                                    {
                                        
var flage = action.result.success;
                                        
//如果服务器端传过来的数据为true则表示添加成功
                                        if (flage == true)
                                        {
                                            Ext.MessageBox.alert(
'恭喜','添加添加成功!');
                                            newWin.hide();
                                        }
                                    },
                                    
//提交失败的回调函数
                                    failure:function()
                                    {
                                        Ext.Msg.alert(
'错误','服务器出现错误请稍后再试!');
                                    }
                                }
                            );

 

3、关于GridPanel自适应宽度和高度的问题

    GridPanel不能自适应宽度和高度,在使用时一般都是定义宽度和高度,为了解决此问题,网上有一些办法是通过函数来获取window的宽度和高度再处理,这里有一个比较简单的方法。

    将 GridPanel render到Panel去。

var project_panel = {
        id : 'dept-panel',
        border : false,
        layout : 'border',
        title:'项目管理系统',
        items : [Project_grid]
    };


posted @ 2009-01-22 23:07  菜鸟老师  阅读(5420)  评论(0编辑  收藏  举报