0
votes

I'm trying to load a json into my view. Im using phonegap with sencha touch and when I load the app to my phone the json does not load at all.. It works fine in the browser and in the simulator. I would really appreciate some help from the experts

Here is the main code that im trying:

the store:

App.stores.freebees = new Ext.data.Store({ model: 'Freebee', autoLoad: true, proxy: { type: 'ajax', url: 'fixtures/freebees', reader: { type: 'json' } } });

the list view:

App.views.FreebeesList = Ext.extend(Ext.List, { id: 'indexlist', layout: 'fit', store: App.stores.freebees, itemTpl: '{companyName}, {title}, {address}',

listeners: {
    'itemtap': function(list, index, item, obj) {
        Ext.dispatch({
            controller: 'Freebee',
            action: 'showDetails',
            id: list.getRecord(item).data.id,
            lat: list.getRecord(item).data.lat,
            longitude: list.getRecord(item).data.longitude,
            companyName: list.getRecord(item).data.companyName,
            address: list.getRecord(item).data.address,

        });
    }
},
initComponent: function() {
    App.views.FreebeesList.superclass.initComponent.apply(this, arguments);
}

}); Ext.reg('App.views.FreebeesList', App.views.FreebeesList);

the json:

[ { "id": 1, "title": "Freebee 1", "companyName": "Företaget AB 1", "address": "Ekuddsvägen 1 Nacka 131 38 Sweden", "lat": 59.3058, "longitude": 18.1463 }, { "id": 2, "title": "Freebee 2", "companyName": "Företaget AB 2", "address": "Ekuddsvägen 2 Nacka 131 38 Sweden", "lat": 59.305, "longitude": 18.1478 } ]

2

2 Answers

0
votes

From my limited experiece with ST so far, you cant load a file which is on the device like that. You may have to load the json file using a script tag and pass it in as data.

data = [ { "id": 1, "title": "Freebee 1", "companyName": "Företaget AB 1", "address": "Ekuddsvägen 1 Nacka 131 38 Sweden", "lat": 59.3058, "longitude": 18.1463 }, { "id": 2, "title": "Freebee 2", "companyName": "Företaget AB 2", "address": "Ekuddsvägen 2 Nacka 131 38 Sweden", "lat": 59.305, "longitude": 18.1478 } ];

then load it into your store like so:

App.stores.freebees = new Ext.data.Store({ model: 'Freebee', root:data, autoLoad: true, proxy: { type: 'ajax', url: 'fixtures/freebees', reader: { type: 'json' } } });

(added root:data)

0
votes