Sencha touch 如何将JSON响应的内部属性与Sencha代理一起使用

Sencha touch 如何将JSON响应的内部属性与Sencha代理一起使用,sencha-touch,extjs,sencha-touch-2,Sencha Touch,Extjs,Sencha Touch 2,JSONP代理在很大程度上为我工作,但我需要根据JSON响应中的一些嵌套属性设置模型的属性。在不扩展Reader类的情况下,我不知道如何做到这一点,但我认为可能有一种更简单的方法,我只是错过了 我的配方模型: Ext.define('NC.model.Recipe', { extend: 'Ext.data.Model', config: { fields: [ { name: 'name', type: 'string' }, { name: 'imag

JSONP代理在很大程度上为我工作,但我需要根据JSON响应中的一些嵌套属性设置模型的属性。在不扩展Reader类的情况下,我不知道如何做到这一点,但我认为可能有一种更简单的方法,我只是错过了

我的配方模型:

Ext.define('NC.model.Recipe', {
  extend: 'Ext.data.Model',
  config: {
    fields: [
      { name: 'name', type: 'string' },
      { name: 'image', type: 'string' },
      { name: 'preparationText', type: 'string' },
      { name: 'ingredientsText', type: 'string' },
      { name: 'servings', type: 'string' }
    ]
  }
});
我的商店:

Ext.define('NC.store.Recipes', {
  extend: 'Ext.data.Store',

  config: {
    model: 'NC.model.Recipe',
    storeId: 'Recipes',
    proxy: {
      type: 'jsonp',
      url: 'http://anExternalSite.com/api',
      callbackKey: 'callback',
      filterParam: 'text',
      extraParams: {
        type: 'Recipe'
      },
      reader: {
        type: 'json',
        idProperty: 'uuid',
      }
    }
  }
});
JSON格式:

[
  {
    uuid: "/UUID(XXXX)/",
    name: "Spicy Peanut Noodle Salad",
    image: "http://someplace.com/noodle-salad.jpg",
    properties: {
      preparationText: "Make it all nice and stuff",
      ingredientsText: "Heaps of fresh food",
      servings: "serves 4",
    }
  },
  { ... },
  { ... }
]
我希望将这3个“属性”——
preparationText
ingredientsText
servings
,放置在模型中,但当前仅显示id、名称和图像。是什么方法使这项工作?如果它确实涉及到扩展Reader类,那么一些方向将是很好的


谢谢。

您可以像这样更改代码以访问嵌套值

{ name: 'preparationText', type: 'string', mapping: 'properties.preparationText' },

此映射路径应开始排除根元素。

Brilliant!谢谢我不知道为什么这在文档中没有更突出一点。。。