【问题标题】:Extjs 4 mvc: Reference errorExtjs 4 mvc:引用错误
【发布时间】:2013-10-22 14:10:05
【问题描述】:

当我尝试从 URL 获取值以设置按钮是否被禁用时,我在视图中收到以下错误。

ReferenceError: getUrlParams is not defined

为什么定义方法时会出现此错误?

我的观点

Ext.define('AM.view.commission.CommissionList' ,{
    extend: 'Ext.grid.Panel',
    alias: 'widget.commissionlist',

    store: 'ActiveCommissions',

    initComponent: function() {

        this.columns = [
            {header: 'From', dataIndex: 'from', flex: 2},
            {header: 'To',  dataIndex: 'to',  flex: 2},
            {header: 'Status',  dataIndex: 'status',  flex: 5},
            {header: 'Levels',  dataIndex: 'levels',  flex: 5},
            {header: 'Payment Period',  dataIndex: 'paymentPeriod',  flex:5 }
        ];
        this.buttons = [ {
            id:'addCommissionBtn',
            text : 'Add commission',
            action: 'createcommission',
            disabled: getUrlParams
        }];

        this.callParent(arguments);

    }
    ,getUrlParams: function() {
          var params = Ext.urlDecode(window.location.search.substring(1));
          return params['edit'] || null;
    }
});

【问题讨论】:

    标签: javascript model-view-controller extjs extjs4


    【解决方案1】:

    你缺少的this,改成:

    disabled: this.getUrlParams()
    

    编辑:

    在您的 getUrlParams 方法中,您需要返回一个 Boolean 值,如下所示:

    return params.edit === 'true';
    

    【讨论】:

    • 啊,是的,快把我逼疯了...这样我会返回“真”或“假”,但它一直将禁用设置为“假”,即使这应该是“真”,我必须将返回值转换为布尔值才能生效吗?
    • 如果params['edit'] 是一个字符串,它将是truedisabled
    • 是的,我在返回之前做了一个console.log(params['edit']);,它被返回为truefalse,但按钮仍然被禁用......你知道这是为什么吗?
    • 但是您将 true 值传递给 disabled 属性,您在期待什么?
    • 对不起,我的意思是无论我返回 true 还是 false 按钮都被禁用
    猜你喜欢
    • 2013-06-28
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多