Sencha Premium Member
Custom field type (json <-> object)
I have a small issue and I can't decide what would work best:
I have a model that has some regular typed fields (string, int, etc), but it has a json as well. This is set to string of course, but I want to be able to make the conversion between the json string and the object it represents as seamless as possible. So that when I sync the store the database will have it as json string and if I load it it will be an object in the store. (The store the model uses actually has an SQL proxy.)
I guess I can use the convert function to do the jsonstring->object conversion upon reading.
For the other direction (writing) I have a few ideas:
1. I can override the toString method of the field and so in the proxy this will be called, which will make the object->jsonstring conversion.
2. I can write my own writer which will check if the field is an object and if so, make the conversion.
3. I can have a simple jsonstring field that always contains the jsonstring and have the "real" object somewhere else in my model object. Maybe a custom property, or in another field.
4. I was looking at an encode/decode property in the Field class but there's not much information on those, can those help?
Or is there any other solution that would help here? I feel the toString() solution is hack-ish and writing a new Writer is cumbersome..
I'd really appreciate any help!
Tags for this Thread