简体   繁体   中英

Sencha Touch - Aliases for model field names

I have a bunch of code for viewing data from a Store that I want to use across multiple applications with minimal changes; however, the data is being loaded from a different REST service depending on the application, and the services sometimes have different names for the same field.

Is there any way I can tell the Store, Proxy, Model, Field, or something else to use an "alias" to get around this problem? As in, I want a field named "city", but when the store loads its data, it assigns to "city" the data from the field "pr_city" in the JSON response.

My response looks like this:

{
"d" : [
    { pr_city: "Denver", ... },
    { pr_city: "Chicago", ... },
    { pr_city: "Miami", ... }
]
}

Turns out there is a "mapping" property in the config for field objects.

fields = [
    { name: 'city', mapping: 'pr_city' }
]

found it in Sencha Touch - How to get list itemtpl to display JSON child objects? , credit to Evan Trimboli.

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