如何使用 ExtJS 5 Ext.data.Model 字段参考(与 ExtJS 4 中的 belongsTo 相比)
How to use ExtJS 5 Ext.data.Model Field reference (in comparison to belongsTo in ExtJS 4)
我在 Ext.data.Model 中使用 belongsTo,它就像魅力一样工作,thread.getCustomer(function(record) {[…]})
加载客户:
Ext.define('MyApp.model.Thread', {
extend: 'MyApp.model.Base',
requires: [
'MyApp.model.Customer'
],
idProperty: 'thread_id',
fields: [
{name: 'thread_id', type: 'int'},
{name: 'thread_customer_id',type: 'int'},
],
belongsTo: {
model: 'MyApp.model.Customer',
name: 'Customer',
primaryKey: 'customer_id',
foreignKey: 'thread_customer_id'
}
});
但是,我收到来自 Ext 的警告:
[W] Use of "belongsTo" is obsolete in MyApp.model.Thread
我试图将其转换为字段定义中的引用:
Ext.define('MyApp.model.Thread', {
extend: 'MyApp.model.Base',
requires: [
'MyApp.model.Customer'
],
idProperty: 'thread_id',
fields: [
{name: 'thread_id', type: 'int'},
{
name: 'thread_customer_id',
type: 'int',
reference: 'MyApp.model.Customer'
}
]
});
或
reference: {
type: 'MyApp.model.Customer',
role: 'customer',
association: 'Customer',
inverse: 'thread'
}
或
reference: {
type: 'Customer',
role: 'customer',
association: 'Customer',
inverse: 'thread'
}
不起作用。
在 中找不到任何有用的东西http://docs.sencha.com/extjs/5.0/core_concepts/data_package.html或http://docs.sencha.com/extjs/5.0/whats_new/5.0/extjs_upgrade_guide.html
你们中有人运气好吗?
我遇到了完全相同的问题,这个链接帮助了我:http://www.sencha.com/forum/showthread.php?285478-Nested-stores-associated-model-doesn%C2%B4t-contain-any-store
它给了我这个:
Ext.define('MyApp.model.Base', {
extend: 'Ext.data.Model',
schema: {
namespace: 'MyApp.model'
}
});
Ext.define('MyApp.model.Application', {
extend: 'MyApp.model.Base',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'auto' },
{ name: 'desc', type: 'auto' }
]
});
Ext.define('MyApp.model.ApplicationVersion', {
extend: 'MyApp.model.Base',
fields: [
{ name: 'id', type: 'int' },
{
name: 'appid',
type: 'int',
reference: {
type: 'Application',
role: 'application',
inverse: 'versions'
}
},
{ name: 'version', type: 'auto' }
]
});
现在我有一个一对多的关联,它有效:
> a = Ext.create(MyApp.model.Application, {desc: 'My description'})
constructor {data: Object, session: null, internalId: 30, …}
> a.versions().add({version: '2.5'})
[constructor]
> a.versions().first().application.get('desc')
"My description"
相关文章:
- 什么's extjs中的mon()和on()之间的区别
- 当在EXTJS中的网格中使用时,afterrender不适用于组合框
- 使用 ExtJS 中的函数将元素附加到数组
- 如何从 ExtJs 中的属性文件中读取值
- ExtJS中的浮动组件
- ExtJS中的评分表
- 组合框extjs中的Textfield而不是fieldlabel
- 使用extJS中的分页功能对存储进行筛选
- 返回summaryType ExtJs中的浮点值
- 在单元格编辑时获取extjs中的行数据
- 如何在extjs中的标题栏上临时展开鼠标上折叠的面板
- 如何实际销毁ExtJS中的组件
- 单击“ExtJS”中的“事件/侦听器”
- 检查网格插件 ExtJs 中的新元素
- Ext.apply 不适用于 ExtJS 中的侦听器
- 如何处理 ExtJs 中的异常“无法调用方法 getRange of null”
- 如何在 ExtJS 中的分组网格中禁用折叠
- 将自定义项添加到 extjs 中的图表图例中
- 如何从视图中的菜单项中激发事件,并在ExtJS中的控制器中捕获它
- 通过extjs中的焦点文本字段打开窗口