首页 > 解决方案 > 我无法在 viewController 中获取 Ext.MessageBox 的实例

问题描述

Ext.define('mondernTunes.view.main.MainView', {
    extend: 'Ext.Container',
    xtype: 'mainview',
    controller: 'MyMainViewController',
    viewModel: {
        type: 'mainviewmodel'
    },
    items: [{
        xtype: 'component',
        html: '<a style="font-size:24px" target="_blank" href="https://docs-devel.sencha.com/extjs/7.0.0-CE/guides/quick_start/What_You_Will_Be_Coding.html">Quick Start Tutorial Here</a><p>'
    }, {
        xtype: 'displayfield',
        reference: 'df',
        bind: {
            value: 'clickTime'
        }
    }, {
        xtype: 'button',
        text: 'Click Me!',
        handler: 'onButtonClick'
    }, {
        xtype: 'button',
        text: "say hello",
        handler: "sayHello" //  will call sayHello in viewController
    }]
})

Ext.define('mondernTunes.view.main.MyMainViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.MyMainViewController',
    requires: ['Ext.MessageBox'],

    sayHello: function (button) {
        Ext.MessageBox.alert("hello");
    }
})

问题: 控制台给我一个错误:

Uncaught TypeError: Ext.MessageBox.alert is not a function

我如何获得Ext.MessageBoxin的实例viewController

标签: extjs

解决方案


试试Ext.Msg.alert("hello"); 而不是Ext.MessageBox.alert("hello");


推荐阅读