2011-12-20 6 views
0

ネストされたJSONをストアにロードしたいが、データが正しくマッピングされていない。 1つのregModelで問題はありませんが、私は関連付けを行うことができません。Sencha TouchのネストされたJSON - アソシエーション付きストアロード

// JSON in test.json 

{"message" : { 

"returnCodes": [ 
     { 
      "value": "0", 
      "code": "200", 
      "description": "OK" 
     }, 
     { 
      "value": "0", 
      "code": "200", 
      "description": "OK" 
     } 
    ] 
}} 

// Model with associations 

Ext.regModel("ReturnCode", { 

    fields : [{ 
     name : "value", 
     type : "string" 
    }, { 
     name : "code", 
     type : "string" 
    }, { 
     name : "description", 
     type : "string" 
    }], 

    belongsTo: "Message" 
}); 

Ext.regModel("Message", { 

    hasMany: { 
     model : "ReturnCode", 
     name : "returnCodes" 
    } 
}); 

// Store 
var jobStore = new Ext.data.Store({ 

model : 'Message', 
autoLoad: true, 

proxy : { 
type : 'ajax', 
url: 'test.json', 

reader : { 
    type : 'json', 
    root : 'message.returnCodes'   
} 
}}); 

// List 
var list = Ext.extend(Ext.List, { 

fullscreen : true, 
store : jobStore, 
grouped : false, 
itemTpl : '<div>{code}</div>'  // no output 

}); 

私が店に見てみると、すべてのデータは、データセクション内のストアオブジェクトが、何の生の部分に格納されます。両方のreturnCodeオブジェクトのリストでは、リスト項目が作成されますが、マッピングが成功しなかったためにデータで満たされません - > itemTplはデータを取得しません。

答えて

0

メッセージモデルを宣言してから、associationKey:'returnCodes'をメッセージモデル内のhasMany{}に追加してください。また、リーダーのルートをmessageに変更します。

This reference could also be of use to you.

関連する問題