javascript - this.up() 不是函数 EXTJS

标签 javascript extjs web-applications extjs4 sencha-touch

我想从 Controller 将数据提交到服务器。 代码如下:

renterForms: function() {
    var items3 = [{
        xtype:'foresto-renterdata',
        scrollable: true,
        scope: this,
        renderTo: 'mainPart',
        handler: function() {
            this.action3.hide();
        }
    },{
        text: 'Submit',
        ui: 'confirm',
        scope: this,
        handler: function() {
            var form = this.up('foresto-rentertype');
            if (form.isValid()) {  
                form.submit({
                    success: function(form, action) {
                        Ext.Msg.alert('Success', action.result.msg);
                    },
                    failure: function(form, action) {
                        Ext.Msg.alert('Failed', action.result.msg);
                    }
                });
            } else { /
                Ext.Msg.alert('Error', 'Please correct form errors.')
            }
        }

在 Chrome 调试器中,我看到下一个错误:

Uncaught TypeError: this.up is not a function.

出了什么问题?这是获取和提交数据的好方法吗?

附注POST 请求的 url 在表单代码中定义

最佳答案

scope: this

这是扰乱处理程序函数内部范围的实际问题。去掉它就可以解决up函数了。

您可以使用以下示例 fiddle 查看具有范围的行为: https://fiddle.sencha.com/#view/editor&fiddle/2nhv

当定义“scope:this”时,构建组件时的范围将被使用并注入(inject)到处理函数中。它相当于显式编写 handlerFn.bind(this) ,它只是绑定(bind)不同的作用域并返回一个新函数。

关于javascript - this.up() 不是函数 EXTJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53204369/

相关文章:

javascript - 具有字符重复的字符串

javascript - 一键保存多个选项卡面板

python - 是否可以部署使用一台 Bokeh 服务器的 Bokeh 应用程序来为多个用户提供服务,而无需使用 Flask 等其他框架?

javascript - 如何使用 firebase 函数创建 api

javascript - Spring、Thymeleaf 和异步数据加载

javascript - 何时使用 useImmer 和 useState?

javascript - 在 Ext JS 4 或 JavaScript 中解析 JSON

javascript - Extjs 表单和文本区域无法处理带尖括号的输入 ('<>' )。奇怪的行为,用户界面就死了

python - 通过 VB 运行 Python 脚本时遇到问题

java - Java Web 应用程序的任务模式