Extjs存储数据模型子字段空错误
当我尝试将远程数据加载到网格时,子字段出现以下错误:Extjs存储数据模型子字段空错误,extjs,null,store,datamodel,Extjs,Null,Store,Datamodel,当我尝试将远程数据加载到网格时,子字段出现以下错误: Cannot read property 'id' of null 我的数据模型: Ext.define('ruleDataModel', { extend: 'Ext.data.Model', fields: [ { name: 'id'}, { name: 'createTime', type:'date', dateFormat: 'timestamp
Cannot read property 'id' of null
我的数据模型:
Ext.define('ruleDataModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id'},
{ name: 'createTime', type:'date', dateFormat: 'timestamp', convert:function(v,j){ return (v != null?new Date(v):null);}},
{ name: 'discountPercent'},
{ name: 'discountAmount'},
{ name: 'discountOverSalePriceFlag', type: 'boolean'},
{ name: 'minSalePriceTotal'},
{ name: 'maxCount'},
{ name: 'execOrder'},
{ name: 'clearanceIncludedFlag', type: 'boolean'},
{ name: 'relatedProductMinCount'},
{ name: 'promocodeRuleTypeName', mapping: 'promocodeRuleType.friendlyType'},
{ name: 'groupName'},
{ name: 'productTypeId', mapping: 'productType.id', defaultValue: ''},
{ name: 'productTypeName', mapping: 'productType.name', defaultValue: ''},
{ name: 'relatedProductTypeId', mapping: 'relatedProductType.id', defaultValue: ''},
{ name: 'relatedProductTypeName', mapping: 'relatedProductType.name', defaultValue: ''}
],
idProperty: 'id'
});
返回的JSON数据:
{totalCount: 1, root: [{"productType": {"name":
...
"relatedProductType":null,
...
"execOrder":0,"id":11}]}
检查以下事项:
ruleDataModel
还是类似于foo.bar.ruleDataModel
对于子字段,数据模型的定义应确保:
Ext.define('ruleDataModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id'},
{ name: 'createTime', type:'date', dateFormat: 'timestamp', convert:function(v,j){ return (v != null?new Date(v):null);}},
{ name: 'discountPercent'},
{ name: 'discountAmount'},
{ name: 'discountOverSalePriceFlag', type: 'boolean'},
{ name: 'minSalePriceTotal'},
{ name: 'maxCount'},
{ name: 'execOrder'},
{ name: 'clearanceIncludedFlag', type: 'boolean'},
{ name: 'relatedProductMinCount'},
{ name: 'promocodeRuleTypeName', mapping: 'promocodeRuleType.friendlyType'},
{ name: 'groupName'},
{ name: 'productType.id', mapping: 'productType', convert:function(v,j) { console.log(v,j); return (v != null?v.id:"");}},
{ name: 'productType.name', mapping: 'productType', convert:function(v,j) { console.log(v,j); return (v != null?v.name:"");}},
{ name: 'relatedProductType.id', mapping: 'relatedProductType', convert:function(v,j) { console.log(v,j); return (v != null?v.id:"");}},
{ name: 'relatedProductType.name', mapping: 'relatedProductType', convert:function(v,j){ console.log(v,j); return (v != null?v.name:"");}}
],
idProperty: 'id'
});
区别在于
正确的一点:
{ name: 'productType.id', mapping: 'productType', convert:function(v,j) { console.log(v,j); return (v != null?v.id:"");}},
错的一个:
{ name: 'productTypeId', mapping: 'productType.id', defaultValue: ''}
1.它是唯一的ruleDataModel,当“relatedProductType”不为null时,它可以完美地运行。。。2.Json是绝对正确的,我用Json查看器进行了尝试,结果显示正确。3.一般来说,“映射”用法防止Extjs给出错误。然而,在这种情况下,我总是得到同样的错误。。。