Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

cordova - json not loading in iphone device while using sencha touch and phonegap

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 } ]

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...