2012-03-15 7 views
0

JSONPプロキシは主に私の仕事ですが、JSON応答のネストされたプロパティに基づいてモデルのプロパティを設定する必要があります。私はReaderクラスを拡張せずにこれを行う方法を理解することはできませんが、私がただ欠けている簡単な方法があるかもしれないと考えました。 Sencha ProxyでJSON応答の内部プロパティを使用する方法

マイレシピモデル:

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 'プロパティ' - preparationTextingredientsText、そしてservings、モデルに配置されるが、現在のところid、name 、そしてイメージはあります。この作業を行う方法は何ですか? Readerクラスの拡張が必要な​​場合は、いくらかの方向性があります。

ありがとうございました。

答えて

2

あなたはルート要素を除く開始する必要があり、ネストされた値

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

このマッピングのパスにアクセスするには、次のようにコードを変更することができます。

+0

ブリリアント!ありがとう。なぜこれがドキュメントでもう少し顕著ではないのかわかりません... – kmc

関連する問題