【发布时间】:2017-01-07 17:57:57
【问题描述】:
我有以下型号和商店。
型号:
Ext.define('TruckTask.model.Company', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{name: 'id', type: 'int', defaultValue: null},
{name: 'name', type: 'string'},
{name: 'site', type: 'string'},
{name: 'createdDate', type: 'date',
convert: function(rawValue, model) {
var intDate = parseInt(rawValue);
if(intDate > 0){
return Ext.util.Format.date(new Date(intDate), 'd.m.Y');
}
if(typeof(rawValue) == 'object'){
return rawValue;
}
}
},
{name: 'langId', type: 'int'}
]
});
商店:
Ext.define('TruckTask.store.Company', {
extend: 'Ext.data.Store',
requires : [
'TruckTask.model.Company',
'TruckTask.config.SecureRestProxy'
],
alias: 'store.company',
storeId: 'company',
model : 'TruckTask.model.Company',
autoLoad: true,
autoSync: true,
proxy: {
type: 'secure-rest',
reader: {
type: 'json'
},
writer: {
type: 'json'
},
api: {
read: '/api/company',
create: '/api/company',
update: '/api/company',
destroy: '/api/company'
}
}
});
我使用网格面板来列出这些模型。但是我通过另一种形式创建新模型。
在网格中我定义了商店:
store: {
type: 'company'
},
并且表单的提交处理程序有实现:
var record = this.getViewModel().get('rec');
var companyStore = Ext.data.StoreManager.lookup('company');
companyStore.add(record);
所以记录立即出现在网格面板中,但没有 createdDate 字段值。该值来自服务器响应。
当我得到服务器响应时,如何在网格面板中更新此记录?
【问题讨论】:
-
它应该自动这样做。如果没有,请制作一个可验证的最小示例来展示该问题。
-
是的,我期待这样的行为,但实际上我什至无法点击新添加的行。它显示在网格中,但是当我单击它时无法选择它。它是否与我的技巧有关,以避免由 ext js 生成的模型 id。请查看在商店中添加事件侦听器。当我向存储添加新记录时,它通过模板
- 获取 id。我在服务器端收到错误。 -
我在使用带有分组的网格时遇到了类似的行为,这是由 ExtJS 错误引起的。您在网格中使用分组吗?
-
不,我不使用
标签: extjs extjs6 extjs6-classic extjs-grid extjs-stores