简体   繁体   English

Sencha Touch - model 字段名称的别名

[英]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.但是,数据是从不同的 REST 服务加载的,具体取决于应用程序,并且服务有时对同一字段具有不同的名称。

Is there any way I can tell the Store, Proxy, Model, Field, or something else to use an "alias" to get around this problem?有什么方法可以告诉商店、代理、Model、字段或其他使用“别名”来解决此问题的方法? 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.如,我想要一个名为“city”的字段,但是当商店加载其数据时,它会将 JSON 响应中字段“pr_city”的数据分配给“city”。

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?Sencha Touch 中找到它 - 如何获取列表 itemtpl 以显示 JSON 子对象? , credit to Evan Trimboli. ,归功于埃文·特里姆博利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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