-
14 May 2012 5:47 AM #31
Hi thanks again I think I'm on the right path now. The whole naming thing is not a big deal i just made a model that reflects the names exactly from the xml. Maybe in a later point I can try to figure out how I could change this. For now I made a new model and a store with an xml proxy. I'm able to load the whole data into the store.
My model
And my storePHP Code:Ext.define('swissunihockey.model.Test', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'id',// Every model must start with an id of type int
type: 'int'
}, {
name: 'title',
type: 'string'
}, {
name: 'link',
type: 'string'
}, {
name: 'description',
type: 'string',
}, {
name: 'pubDate',
type: 'int'
}, {
name: 'bildgross',
type: 'string'
}, {
name: 'bildklein',
type: 'string'
}
]
}
});
So now I need to copy this in an store with a model that has the type sqlitestorage?PHP Code:Ext.define('swissunihockey.store.Test', {
extend: 'Ext.data.Store',
requires: [
'swissunihockey.model.Test',
'Ext.data.reader.Xml'
],
config: {
model: 'swissunihockey.model.Test',
proxy: {
type: 'ajax',
url: 'http://swissunihockey.xservice.ch/xml/newsdata.aspx',
reader: {
type: 'xml',
record: 'item',
rootProperty: 'xml'
}
}
}
});
Again thank you so much for your help I really appreciate it!
Greetings eryx
-
14 May 2012 6:09 AM #32
Hey eryx, great stuff. I think that mapping would fairly easily deal with the difference but if it's nothing to you it doesn't matter. I think the names look better in german anyway!!
So now you need to create a new store with the sqlite proxy on it, and copy across the data.
I've done exactly this in a project myself - I've copied the code below.
All you need to do is run this code when the XML store has loaded, and you've created the sqlite store (you might be better off giving these stores different names... but whatever).
The listener here is useful as I don't hide the loading dialog from the user until this listener fires - I don't want them thinking the whole load/save thing has finished before I can guarantee that the data is now in the database.
Code:var writeListener = function(targetStore) { sqliteStore.un('write', writeListener, this); // you can put some code here that you want to run when the sqlite store has saved to the db successfully }; sqliteStore.removeAll(); xmlStore.each(function(record) { sqliteStore.add(record); }); sqliteStore.on('write', writeListener, this); sqliteStore.sync();
-
14 May 2012 6:21 AM #33
WoW that was easy! Just used your posted code and now I got the data in the db!
Will need to clean up my whole code and then I can post the full solution for future questions related to that.
Thank you so much! Now I'm happy
greetings Eryx
-
14 May 2012 1:35 PM #34
Found a bug:
Add new person, click to edit, rename to something else, tap save. data is updated in db, but List is not synced.
-
14 May 2012 9:50 PM #35
Which ST2 version is that on?
A workaround would be to save the phantom record first, and add it to the store after it's been saved. The issue is it's being added to the list before it has an id; when the record is saved to sqlite it's given an id, and then touch tries to update the list, but because there's no id... no match and no update.
It's an annoying bug... let me have a look into how localstorage deals with this.
Also, you could just reload the store after every write operation but with large data sets that will come with overhead.
-
15 May 2012 1:06 AM #36
So the exact same issue happens if you use the localstorage proxy... the bug here is in the demo app, not the sqlite proxy, and the workaround is simple as explained... just save the record and add it to the store on the save record callback (this is incidentally why the proxy must go on the record - I've encountered this issue before!!)
No record should ever go into a store unless it has an id, and it just so happens that if Sencha Touch uses IDs related to the local storage protocol (be it web storage or sqlite db) those are not created until the record has been saved. IMO a store should be able to handle phantom records and have some way of updating phantom records that are now saved in the store's dataviews, but that's an issue for the base code.
-
15 May 2012 12:33 PM #37
Running into loads of issues trying to build production/testing apps with this thing... will see what solutions I can come up with.
-
15 May 2012 12:41 PM #38
-
15 May 2012 12:53 PM #39
Hey, which branch from github could you package up without any issues? Very keen to hear! I'll sort this tomorrow. Had one of those days where nothing goes right aggh!
What errors do you get now? For me (on windows) I get a dom level 18 exception on build.
*EDIT: bizarrely it does however let me build the demo. IDKWTFIGOH. I just made that up. But the IGOH means is going on here, you should be able to work out the rest ;-)
Will take another look tomorrow but any help on what works / did work would be great.
-
15 May 2012 2:07 PM #40
I unfortunately never had any luck building the demo on any version of it. I just had luck building my own app which uses the sqlite proxy. When trying to build the sqlite demo app I was also getting those DOM 18 errors. I kind of gave up trying to get a build working because I needed to fix other things with my app and phonegap.


Reply With Quote