View Full Version : Setting up initial data in Sencha / PhoneGap app

23 Oct 2011, 4:41 AM
Hi there,

I'm currently working on a Sencha / PhoneGap app which uses LocalStorage to store data offline, with occasional AJAX syncs to a set of web services.

Part of the app includes a basic content library, each content item consisting of a title and some body text. When the app launches, it will contain an initial set of content, and occasionally it will check a web service to see if any new content items are available for download. When they are, they will be added to the local data store.

I'm wondering what is the recommended way to set-up the initial data-store with the content included with the app. Presumably I could dump it all into a JSON file, and on first-run I can import it all into the data store. On subsequent launches, the database will already be populated and I can skip that step.

Is that how you would do it? Is there a better way? I can't see a problem with that approach, other than perhaps a slightly longer launch-time the first time the app is run.

Would be grateful for any pointers.


23 Oct 2011, 11:56 PM
If i understand what you want:

You have a default JSON file for exemple with defaults data, and you want to give this data to you store when the internet connexion is close.

You can try and continue by this way:

You have the default store who get data in the JSON:

app.stores.defaultStore = new Ext.data.Store({
model : 'Model',
proxy: {
type: 'ajax',
url: default.json,
reader: {
type: 'json',
autoLoad: true

after, in your file where you want to decide which store to take according the connexion

app.stores.ListStore = new Ext.data.JsonStore({
model : 'Model',
setObj: function (JsonObj) {
this.JsonObj = JsonObj;
WPApp.stores.DirectoryItemListListStore.load({data: this.JsonObj});

WPApp.views.ResultPanelList = Ext.extend(Ext.List,{
fullscreen: true,
scroll: 'vertical',
itemTPL: '',
if (WIFI Connexion On)
store: app.stores.ListStore,

I never did that, but it can be a way ...
Hope this helps

24 Oct 2011, 3:45 AM
Thanks for the reply - that's not quite what I was after.

Ignore the fact that I'm syncing from a web-service, the questions would be the same if my application *only* ran offline.

I'm using LocalStorage to handle the stores, and there is some initial data that needs to be in the store before the app runs for the first time. So for example, lets say there was a registration form where the user chooses from a list of countries, and the countries are all in LocalStorage.

The first time that the app runs, the LocalStorage will be empty, and I will want to add the list of countries to the local database before the app finishes launches. The second time the app runs, this will already have happened, and the countries will already exist in the database.

So obviously one way to do this is to store the country list in a text file, and then each time I launch the app, I check to see if the LocalStorage is empty. If it is, I load in the text file and pre-populate the database. If the LocalStorage is not empty, I don't need to do this.

Is that the best way to achieve this, or is there a different way to pre-populate LocalStorage for the first time?


24 Oct 2011, 3:56 AM
Hum yes ... you can maybe at the first time in you application set some config:
You can do a app.config.js and put:

app.config = {

host: 'http://localhost:8888/app/',
DataPath: 'data/',
PhpPath: 'app/php/',

I use this config for define some paths but you can use for load some data i think.
This app.config.js must be called in index.html just after your app.js.

or look after this way ...


Hope this helps