Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Extjs存储数据模型子字段空错误_Extjs_Null_Store_Datamodel - Fatal编程技术网

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

  • 您的json可能有问题。有一种简单的方法可以测试json是否正确。将该json保存在.json文件中,并在浏览器中打开该文件。若浏览器能够正确打开json文件,那个么您的json是正确的,否则就不正确


  • 对于子字段,数据模型的定义应确保:

    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给出错误。然而,在这种情况下,我总是得到同样的错误。。。