admin管理员组

文章数量:1379528

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 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');
    }
});
Share Improve this question edited Dec 8, 2017 at 12:30 Lorenz Meyer 20k23 gold badges83 silver badges128 bronze badges asked Aug 21, 2015 at 20:40 developer747developer747 16k28 gold badges104 silver badges156 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

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

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

本文标签: javascriptEXTjs Uncaught TypeError controllersetView is not a functionStack Overflow