【问题标题】:Extjs6 apply property from config via functionExtjs6 通过函数从配置应用属性
【发布时间】:2015-09-24 08:26:59
【问题描述】:

我以前用extjs4写过这个:

Ext.define('Superstore', {
    extends: 'Ext.data.Store'

    config : {
        customer : null,
    },

    applyCustomer : function (value) {
        this.customer = value;
    },

    model : 'Supermodel'

});

我在 extjs6 中尝试了同样的方法,但没有成功:'

Ext.define('Supermodel', {
    extend: 'Ext.data.Model',

    requires: ['Ext.data.reader.Json', 'Ext.data.proxy.Rest'],

    config: {
        customer: null
    },

    fields: [
        {name: 'id', type: 'string'},
        ...
    ],

    proxy: {
        type: 'rest',
        url: '/customers/{customer}/users',
        reader: {
            type: 'json'
        }

    },

    applyCustomer: function (value) {
        this.customer = value;
        this.proxy.url.replace('{customer}', value);
    }

});

他们消除了魔法吗? 或者有没有其他更好的方法来构建我的 url,就像在我的代码中一样? 我已经看到了一些解决方案,但没有一个适合我的应用程序。 我通过登录后由后端发送的会话获取 customerId。我会通过 StoreManager 获取商店,获取客户记录并将其应用于代理。

提前致谢。

【问题讨论】:

    标签: javascript extjs store extjs6


    【解决方案1】:

    如果您不需要操作该值,请改用update 函数:

    updateCustomer: function(newValue){
        this.proxy.url.replace('{customer}', newValue);
    }
    

    (并删除applyCustomer函数)

    【讨论】:

    • 这个函数是自动执行的吗?
    • 它不工作。该功能未执行。 url 仍然是customers/%7Bcustomer%7D/users(至少应该是/customers/null/users
    • updateCustomerapplyCustomer 返回 null 或 undefined 时永远不会被调用。这是使用updateCustomer() 的好处之一。是的,applyCustomer 是一个自动生成的方法,它应该返回一个值。所以你在 ExtJs 4 中所做的也是错误的。 sencha.com/forum/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    相关资源
    最近更新 更多