简体   繁体   中英

Sencha Touch 2 - Customize model population from a store

I'm building a sencha (sencha touch 2) app which it gets some json data from a proxy. I'm populating a store so I have a model (with some fields) and a view which it show gotten data.

I need to modify some data received by proxy with a json reader and before to be saved into a model I need to modify some of the model fields.

Let's say I have the fields (id, title, text), I'm receiving non parsed text and I need to transform url's into a rich text forman like http://whatever

Ok, so, Is there any method to be defined into the store class where it will be executed each time a model is filled up?

For example:

...
customText: function(data) {
    return parseUrlsFromString(data);
}
...

I have, a view, a controller, a store and a model defining the expected behaviour.

Any comment will be appreciated!

After doing some research some guys replied in sencha forum. I share the solution for my question with you:

We need to do a small change to your Model definition. If you set a convert function on the title data field (Model definition), you can do whatever you want to the raw data before it gets added to the Record.

Check out the Types and conversions section of the documentation (near the top): http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Field

Also make sure to read the convert property docs: http://docs.sencha.com/touch/2-0/#!/...ld-cfg-convert

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM