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
Sencha touch JSON解析问题sencha touch 2_Sencha Touch_Extjs_Sencha Touch 2 - Fatal编程技术网

Sencha touch JSON解析问题sencha touch 2

Sencha touch JSON解析问题sencha touch 2,sencha-touch,extjs,sencha-touch-2,Sencha Touch,Extjs,Sencha Touch 2,我有下面的json,需要显示在列表(位置数组)中。我可以使用rootProperty:response.data.locations获得位置数组,但是如何获得成功、徽标和背景图片呢。任何建议都是有益的 Ext.data.JsonP.callback1( { "response": { "success": true, "data": { "logo": "http:\\/\\/www.websiteurl.nl\\/Images\\

我有下面的json,需要显示在列表(位置数组)中。我可以使用rootProperty:response.data.locations获得位置数组,但是如何获得成功、徽标和背景图片呢。任何建议都是有益的

Ext.data.JsonP.callback1(
{
    "response": {
        "success": true,
        "data": {
            "logo": "http:\\/\\/www.websiteurl.nl\\/Images\\/logo.jpg",
            "backgroundpicture": "http:\\/\\/www.websiteurl.nl\\/Images\\/logo.jpg",
            "locations": [
                {
                    "id": "47",
                    "name": " 's-Gravenzande (De Carlton)",
                    "street": "Naaldwijkseweg",
                    "number": "257",
                    "zipcode": "2691 PV",
                    "city": "'s Gravenzande",
                    "province": "9",
                    "phone": "0174-412997",
                    "email": "info@websiteurl.nl",
                    "kvk": "27210224",
                    "lat": "51.988593",
                    "longitude": "4.188087",
                    "slug": "-sGravenzande-De-Carlton",
                    "website": "http:\\/\\/www.websiteurl.nl",
                    "logo": null,
                    "backgroundpicture": null
                },
                {
                    "id": "1",
                    "name": "Achterberg",
                    "street": "Weteringsteeg",
                    "number": "12",
                    "zipcode": "3911 VN",
                    "city": "Achterberg",
                    "province": "7",
                    "phone": "0317-613643",
                    "email": "info@websiteurl.nl",
                    "kvk": "30093218",
                    "lat": "51.976316",
                    "longitude": "5.601611",
                    "slug": "-Achterberg",
                    "website": "http:\\/\\/www.websiteurl.nl",
                    "logo": null,
                    "backgroundpicture": null
                }


            ]
        }
    }
}
);
如果我在我的存储中添加一个listner,然后记录这些内容,那么我就得到了这些值,但我的问题是如何解析它并将其存储在我的存储中

Ext.define("app.store.LocationStore",{
extend:'Ext.data.Store',
id: 'locationStore',

requires: 'Ext.data.proxy.JsonP',

config:{
    autoLoad: 'true',
    model:'app.model.LocationModel',

    proxy:
    {
        type:'jsonp',
        url:'http://www.websiteurl.nl/API/',
        limitParam: false,
        pageParam: false,
        startParam: false,
        extraParams:
        {
            method:'general',
            token: '123456'

        },
        reader:{
            type:'json',
            successProperty: 'success',
            rootProperty: 'response.data.locations'
        }
    },
    listeners:{
        load : function()
        {console.log(this.getProxy().getReader().rawData.response.data.backgroundpicture);
            console.log(this.getProxy().getReader().rawData.response.data.logo);
            console.log(this.getProxy().getReader().rawData.response.success);
            console.log("location store loaded");
        }
    }
}
});

您需要使用and关联根据数据结构构造模型

Ext.define('myApp.model.MyModel', {
    extend: 'Ext.data.Model',
    config: {
        fields  : [
            {
                name : 'success'
            }
        ],
        hasOne : [
            {
                model          : 'myApp.model.Data,
                name           : 'data',
                associationKey : 'data'
            }
        ]
    }
});

Ext.define('myApp.model.Data, {
    extend: 'Ext.data.Model',
    config: {
        fields  : [
            {
                name : 'logo'
            },
            {
                name : 'backgroundpicture'
            }
        ],
        hasMany : [
            {
                model          : 'myApp.model.Location',
                name           : 'locations',
                associationKey : 'locations'
            }
        ]
    }
});

Ext.define('myApp.model.Location', {
    extend: 'Ext.data.Model',
    config: {
        fields  : [
            {
                name : 'id'
            },
            {
                name : 'name'
            },
            {
                name : 'street'
            }
    ...to be continued...

您还可以使用简单的JSONP请求来填充数据并将其添加到存储中。它将是这样的:

Ext.data.JsonP.request({
     url:'http://www.websiteurl.nl/API/',
     callbackKey: 'callback',
     params: {
         method:'general',
         token: '123456'
     },
     success: function(result, request) {
          //result.response.success
          //result.response.data.logo
          //result.response.data.backgroundpicture
          store.add(result.response.data.locations);
     }
});

您的“store”或“model”rootProperty设置是什么?在我的问题中添加了store代码以及如何获取successProperty值?修改答案以包含一个关联以将successlocation模型值获取到我的列表中。你能给我看看它的商店和目录吗。