You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

ExtJS点击按钮弹出表单报错:controller.setView is not a function

Fixing "controller.setView is not a function" Error in ExtJS Dialog Creation

Let's break down this error and get your reportBox dialog working properly when clicking the button:

Root Cause

The Uncaught TypeError: controller.setView is not a function happens because the controller you've assigned to your reportBox dialog isn't a valid ExtJS ViewController instance. ExtJS tries to bind the controller to the view but can't find the core setView method that all proper view controllers inherit.

Step-by-Step Fixes

1. Validate Your reportBoxController Definition

Your reportBox.js references Traccar.view.dialog.reportBoxController, but if this file isn't correctly extending Ext.app.ViewController, it won't work as expected. Make sure your reportBoxController.js looks like this:

Ext.define('Traccar.view.dialog.reportBoxController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.reportBox', // Must match the `controller` config in reportBox.js

    // Add your controller logic here (e.g., form submission handlers)
    onFormSubmit: function() {
        // Example logic: get form values and process
        var form = this.getView().down('form');
        var values = form.getValues();
        // Handle submission
    }
});

Without the extend: 'Ext.app.ViewController' line, the controller won't have the setView method ExtJS expects.

2. Verify Controller Path & Dependencies

Double-check the requires array in reportBox.js to ensure the path to reportBoxController matches your actual file structure. ExtJS is case-sensitive with class paths, so make sure capitalization (e.g., reportBoxController vs ReportBoxController) matches exactly, especially if you're working on a Linux-based server.

3. Test Without Controller (Troubleshooting Step)

To confirm the controller is the issue, temporarily comment out the controller:'reportBox' line in reportBox.js and run your code again. If the dialog pops up without errors, you know the problem is definitely in how your reportBoxController is defined or referenced.

4. Check the BaseEdit Base Class

Your reportBox extends Traccar.view.dialog.BaseEdit. If this base class already defines a controller, it might be conflicting with your custom controller. Review the BaseEdit definition to see if it has a controller config, and adjust your subclass accordingly (either inherit the base controller or ensure your custom controller properly extends it if needed).

Final Test

Once you've fixed the controller definition, run your OnRoutesClick method again. The reportBox dialog should load correctly with the user record and show the test notification button as expected.

内容的提问来源于stack exchange,提问作者Shankar Ghimire

火山引擎 最新活动