一个extjs4.2插件的简单例子

quote: http://whatisextjs.com/extjs/extjs-4-2-plugin-example

 

 

I've enjoyed the 4.2 ExtJS release since it came out; especially the new theme and grids. I recently wanted to "puff in" a Panel for some eyecandy, but I quickly realized it's a bit trickier than you might think.

Screen

Components don't have slideOut or fadeIn methods like Elements do.

It's not a problem in case of "hiding" actions (i.e. slideOut or puff), which you can accomplish by something like component.getEl().slideOut().

However, in the case where you want to "show" a hidden panel (i.e. slideIn), in a case of deferred rendering (i.e. when creating and showing a new panel on the fly), the getEl() doesn't have a DOM element to show yet, until the panel has been rendered.

The fadeIn method is achieved by showing a panel with CSS opacity 0% and then animating it back to 100%.

I ended up solving this via means of a plugin. Can you think of a more elegant solution?

Plugin

Ext.define('Ext.ux.component.FadeInPlugin', {
    extend: 'Ext.AbstractPlugin',
    alias: 'plugin.ux.fadeinplugin',
    requires: ['Ext.fx.Anim'],
 
    init: function (component) {
        Ext.apply(component, {
            style: {
                opacity: 0
            }
        });
        component.fadeIn = this.fadeIn.bind(component);
    },
 
    fadeIn: function () {
        var me = this;
        Ext.create('Ext.fx.Anim', {
            target: me,
            duration: 400,
            from: {
                opacity: 0
            },
            to: {
                opacity: 1
            }
        });
    } // eo fadeIn()
});

Sample Usage

var p = Ext.create('Ext.panel.Panel', {
    id: 'thePanel',
    title: 'Test',
    html: 'Test',
    width: 400,
    height: 300,
    renderTo: Ext.getBody(),
    margin: 50,
    plugins: ['ux.fadeinplugin']
}); // eo panel
p.fadeIn();

View Demo on JSFiddle

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 ExtJS 4.2 中,可以使用 Ext.form.Panel 类来创建表单,然后使用表单的 submit 方法来提交表单。以下是一个简单的示例: ```javascript Ext.create('Ext.form.Panel', { title: 'My Form', width: 300, bodyPadding: 10, renderTo: Ext.getBody(), url: 'submit.php', // 表单提交的 URL items: [{ xtype: 'textfield', name: 'username', fieldLabel: 'Username' }, { xtype: 'textfield', name: 'password', inputType: 'password', fieldLabel: 'Password' }], buttons: [{ text: 'Submit', handler: function() { var form = this.up('form').getForm(); if (form.isValid()) { form.submit({ success: function(form, action) { Ext.Msg.alert('Success', action.result.msg); }, failure: function(form, action) { Ext.Msg.alert('Failed', action.result.msg); } }); } } }] }); ``` 在这个示例中,我们创建了一个 Ext.form.Panel 对象,并设置了一些属性,例如标题、宽度、padding、提交的 URL 等等。我们还添加了两个文本框作为表单的输入项,并为它们指定了 name 属性。最后,我们添加了一个提交按钮,并为它指定了一个事件处理函数。 在按钮的事件处理函数中,我们首先获取表单对象,然后调用表单的 isValid 方法来判断表单是否有效。如果表单有效,我们就调用表单的 submit 方法来提交表单。submit 方法接受一个对象作为参数,可以指定一些回调函数来处理提交成功或失败的情况。在这个示例中,我们分别显示了一个成功或失败的提示框。 当用户点击提交按钮时,表单数据将被发送到指定的 URL。在 PHP 中,你可以使用 $_POST 变量来获取表单数据。例如,如果你的表单中有一个名为 username 的文本框,你可以使用 $_POST['username'] 来获取它的值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值