【问题标题】:ExtJS store foreign key is overriden to zeroExtJS 存储外键被覆盖为零
【发布时间】:2014-03-07 09:49:59
【问题描述】:

我有一个 ExtJS 应用程序,它有两个模型(和相应的商店):Salary 和 Employee。 Salary 对 Employee 有一个外键。

加载 Salary 时,外键被覆盖为 0,为什么会这样?如何防止?

在控制台中:

> s = Ext.getStore('crm.Salaries')
> s.data.items[0].raw
Object {id: 1, date: "2014-03-05 00:00:00", amount: 1000, employee: 6982}
> s.data.items[0].data
Object {id: 1, date: Wed Mar 05 2014 00:00:00 GMT+0100 (CET), amount: 1000, employee_id: 0}

薪酬模式:

Ext.define('Project.model.crm.Salary', {
    extend: 'Ext.data.Model',


    fields: [{
        name: 'id'
    },{
        name: 'date',
        type: 'date',
        dateFormat: Ext.Date.patterns.ISO8601Long
    },{
        name: 'amount',
        type: 'float'
    },{
        name: 'employee_id',
        mapping: 'user',
        type: 'int'
    }],

    syncAssociations: [{
        store: 'Employees', key: 'employee_id'
    }],

    statics: {
        instanceDefaults: {
            amount: 0.0
        }
    }
});

工资商店:

Ext.define('Project.store.crm.Salaries', {
    extend: 'Project.lib.base.Store',
    model: 'Project.model.crm.Salary',

    proxy: {
        type: 'direct',
        api: {
            read: $["crmModule.SalaryController"].list
        }
    },

    requires: ['Project.store.Employees'],
    autoLoad: false,
    remoteFilter: true
});

当我按照我的建议将代理移动到模型时,它不起作用(没有为此代理指定直接函数) - 但这是另一个问题。

【问题讨论】:

    标签: javascript extjs foreign-keys model-associations


    【解决方案1】:

    模型字段定义有问题。对于mapping 属性:

    不要使用数据库表名,

    但真正的协会名称:employee

    真的,改成:

    {
        name: 'employee_id',
        mapping: 'employee',
        type: 'int'
    }
    

    已修复,但我不知道具体原因。 (一些 ExtJS 魔法?)

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 2017-05-08
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      相关资源
      最近更新 更多