1

我为一个带有 sencha touch 的移动应用程序项目工作,我的模型在检索信息时遇到了问题。我将向您展示我的模型和我的 json 文件内容

json文件:(我只是为了测试而变得非常简单,我删除了几何线)

{
        "type": "FeatureCollection",
        "features": [
            {
            "properties": {"graphic": "img/restaurant.png","Name": "Igor Tihonov", "Country":"Sweden", "City":"Gothenburg"}
            }

        ]
}

我的模型:

 Ext.regModel('Features', {
        hasMany: {model: 'Properties', name: 'properties'}

    });


    Ext.regModel('Properties', {
        fields: ['graphic', 'Name', 'Country', 'City'],
        associations: [
            {type: 'belongsTo', model: 'Features'}
        ]
    });

店铺 :

 Ext.data.Store({
        model: 'Features',
        proxy: {
            type: 'ajax',
            url : 'poi2.json',
            reader: {
                type: 'json',
                rootProperty: 'features'
            }
        },
        autoLoad:true
    });

我被封锁已经一个多星期了,我希望你能帮助我!谢谢你

4

1 回答 1

0

如果您不使用“类型”属性,我建议:

  • 失去第一个模型和所有关联
  • 将商店中的模型设置为“属性”(这可行,因为您的 rootProperty 设置为“功能”)
  • 更改您的 JSON,以便属性不是 JSON 更深层次的另一个层次:

    {  
        "type": "FeatureCollection",  
        "features": [  
            {  
                "graphic": "img/restaurant.png",  
                    "Name": "Igor Tihonov",   
                "Country":"Sweden",  
                "City":"Gothenburg"}  
            },  
            {  
                "graphic": "img/restaurant2.png",  
                "Name": "Igor Tihonov2",   
                "Country":"Sweden",  
                "City":"Gothenburg"}    
            }  
        ]  
    }  
    

[编辑]
要保持 json 格式,请使用以下方法:

  • 将根属性设置为“功能”
  • 将仅包含“hasMany”关联的“功能”模型添加到您的属性模型(包含实际字段)
  • 将商店的模型设置为您的特征模型

[/编辑]

于 2012-10-18T00:08:48.517 回答