【问题标题】:EXTjs: Uncaught TypeError: controller.setView is not a functionEXTjs:未捕获的类型错误:controller.setView 不是函数
【发布时间】:2017-12-08 20:30:48
【问题描述】:

我正试图让它在sencha fiddle 中工作。如果我运行它,我会在控制台日志“Uncaught TypeError: controller.setView is not a function”中看到这个错误。只有当我从视图中删除控制器声明时它才有效。我做错了什么?

Ext.define('MyApp.controller.Whatever', {
    extend: 'Ext.app.Controller',
    alias: 'controller.Whatever',
    init: function() {
        alert("Yes!");
    }
});

Ext.define('MyApp.view.Whatever', {
    extend: 'Ext.form.Panel',
    controller: 'Whatever',
    title: 'Hello',
    width: 200,
    html: '<p>World!</p>',
    renderTo: Ext.getBody()
});

Ext.application({
    name: 'MyApp',
    launch: function() {
        Ext.create('MyApp.view.Whatever');
    }
});

根据下面的答案,这个可行

Ext.define('MyApp.controller.Whatever', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.Whatever',
    init: function() {
        alert("Yes!");
    }
});

Ext.define('MyApp.view.Whatever', {
    extend: 'Ext.form.Panel',
    alias:'widget.Whatever',
    controller: 'Whatever',
    title: 'Hello',
    width: 200,
    html: '<p>World!</p>',
    renderTo: Ext.getBody()
});

Ext.application({
    name: 'MyApp',
    launch: function() {
        Ext.create('MyApp.view.Whatever');
    }
});

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    我认为您使用的是 Ext JS 5 或更高版本,所以请使用它。

    Ext.app.ViewController 而不是 Ext.app.Controller。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-19
      • 2012-07-25
      • 1970-01-01
      • 2019-06-06
      • 2019-05-24
      • 2021-12-15
      • 2019-10-26
      相关资源
      最近更新 更多