View Full Version : Sencha Touch Data vs. ExtJS Data

8 Sep 2011, 12:54 PM
Using Sencha Touch's data classes, I have set up a Model and a Store. I have retrieved a collection into the store from a REST service. Next thing I want to do is sync changes back to the service, but the Sencha Touch Writer class and Field class don't seem to support this very well. For example, given the following model:

Ext.regModel('News', {
fields: [
{name: 'id', type: 'int'},
{name: 'newsId', mapping: 'iid', type: 'string'},
{name: 'source', mapping: 'source', type:'string'},
{name: 'title', mapping: 'stitle', type: 'string'},
{name: 'dateModified', mapping: 'tmodified', type: 'date', convert: toDateFromJSON}

When I sync the store to the service, I get something like this on the wire (using json writer):

{"d.results": [
"title":"People will do as they are told by someone who outranks them, but...",
"dateModified": "2010-09-28T12:28:38.323Z"

The service doesn't know anything about "newsId", "source", etc.; so it will fail to accept the request. Notice when I defined my model I mapped the service field names to model field names (e.g. "iid" gets mapped to "newsId").

So I went looking for a way to tell the writer to use the mapped names. Nothing. And I went looking for a way to indicate which fields on my model should be excluded from being persisted. Nothing.

BUT... Interestingly, ExtJS 4's data package does support these concepts. So I know I'm not crazy and someone at Sencha knows these are important. I.e. See ExtJS Writer nameProperty (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.writer.Writer-cfg-nameProperty). And see ExtJS Field persist (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Field-cfg-persist) property.

These seem like pretty hefty pieces of missing functionality from Sencha Touch. I.e. Try to go beyond anything very simple with respect to syncing a store and you're screwed. What are my options?