简体   繁体   中英

EXTjs: Uncaught TypeError: controller.setView is not a function

I am trying to get this to work in sencha fiddle . If I run it I see this error in the console log "Uncaught TypeError: controller.setView is not a function". It works only if I remove the controller declaration from the view. What am i doing wrong?

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');
    }
});

Based on the answer below this worked

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');
    }
});

I think you are using Ext JS 5 or above version so use this.

Ext.app.ViewController instead of Ext.app.Controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM