【发布时间】: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