【问题标题】:Button in Sencha Touch 2 doesn't workSencha Touch 2 中的按钮不起作用
【发布时间】:2014-01-17 13:17:19
【问题描述】:

在 App.js 文件的 launch() 函数中,我有以下代码:

launch: function() {
    // Destroy the #appLoadingIndicator element
    Ext.fly('appLoadingIndicator').destroy();

    // Initialize the main view
    Ext.Viewport.add(Ext.create('SenchaApp.view.Main'));
},

在 View.js 文件中,我有以下代码:

var button = Ext.create('Ext.Button', { text: 'Click me',
                                        handler: function() {
                                              alert('You clicked the button!')
                                      }}
                        );


Ext.define("SenchaApp.view.Main", {
         extend: 'Ext.Panel',
         config: { items: [button]}
});

问题是按钮的事件永远不会触发,所以按钮不起作用。

这是什么原因??

【问题讨论】:

    标签: javascript events button extjs sencha-touch-2.1


    【解决方案1】:

    也许它确实有效,但您没有收到警报 :)

    试试这个:

    var button = Ext.create('Ext.Button', { text: 'Click me',
        handler: function() {
            console.log('You clicked the button!')
            Ext.Msg.alert('hey', 'You clicked the button!');
        }}
    );
    

    【讨论】:

    • 没什么...问题仍然存在。该按钮不可点击。
    【解决方案2】:

    你可以这样使用:

    var button = Ext.create('Ext.Button', {
        text: 'Button',
        handler : function(){alert("You clicked the button!");}
    });
    Ext.Viewport.add({ xtype: 'container', padding: 10, items: [button] });
    

    Ext.create('Ext.Container', {
        items: {
            xtype: 'button',
            text: 'My Button',
            handler : function(){Ext.Msg.alert('Msg','You clicked the button!');}
        }
    });
    

    希望对你有帮助!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-19
      • 1970-01-01
      • 2012-05-05
      相关资源
      最近更新 更多