Ext.form.Panel表单加载

Ext.onReady(function ()
{
    //初始化提示
    Ext.QuickTips.init();
    var productForm = Ext.create("Ext.form.Panel", {
        title: "表单加载示例",
        width: 300,
        frame: true,
        fieldDefaults: {
            labelSeparator: ":",
            labelWidth: 80,
            width: 250,
            margin:5
        },
        renderTo: Ext.getBody(),
        items: [
            { fieldLabel: "产品名称", xtype: "textfield", name: "productName", value: "U盘" },
            { fieldLabel: "金额", xtype: "numberfield", name: "price", value: 100 },
            { fieldLabel: "生产日期", xtype: "datefield", format: "Y-m-d", name: "date", value: new Date() },
            { xtype: "hidden", name: "productId", value: "001" },
            { fieldLabel: "产品简介", name: "introduction", xtype: "textarea" }
        ],
        buttons: [
            { text: "加载简介", handler: loadIntroduction }
        ]
    });
    function loadIntroduction()
    {
        var params = productForm.getForm().getValues();
        productForm.getForm().load({
            params: params,
            url: "/AjaxHandler/productServer.ashx",
            method: "GET",
            waitMsg:"加载中,请稍后……",
            success: function (form, action)
            {
                //加载成功的处理
                Ext.MessageBox.alert("提示", "产品简介加载成功");
            },
            failure: function (form, action)
            {
                //加载失败的处理
                Ext.MessageBox.alert("提示", "产品简介加载失败<br/>原因是:" + action.result.errorMessage);
            }
        })
    }
})
productServer.ashx代码如下:
<pre name="code" class="csharp">public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            //context.Response.Write("Hello World");
            string productId = context.Request.Params["productId"];
            string result = string.Empty;
            if(productId=="001")
            {
                result = "{success:true,data:{introduction:'本产品美观实用,售后服务优秀。'}}";
            }
            else
            {
                result = "{success:false,errorMessage:'数据不存在'}";
            }
            context.Response.Write(result);
        }


 
 
<img src="http://img.blog.csdn.net/20150510171724095?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc2h1eWl6aGk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

你可能感兴趣的:(Ext.form.Panel表单加载)