How to read nested JSON structure with a Sencha Touch Data Model?

前端 未结 2 1480
失恋的感觉
失恋的感觉 2021-02-03 13:18

I\'ve been trying to figure this out all evening but to no avail. I have a JSON structure as follows (coming from another system so I can\'t change its structure):


          


        
2条回答
  •  执念已碎
    2021-02-03 13:46

    Ran into a similar problem recently..I think.

    You need to specify the mapping to the data you want in your model. For example :

    Ext.regModel('Album', {
    fields: [
        {name: 'artist_name', mapping: 'album.artist.name'},
        {name: 'artist_token', mapping: 'album.artist.token'},
        {name: 'album_name', mapping: 'album.name'},
        {name: 'token', mapping: 'album.token'},
        {name: 'small_cover_url', mapping: 'album.covers.s'},
        {name: 'large_cover_url', mapping: 'album.covers.l'}
    ]/*,
    getGroupString : function(record) {
        return record.get('artist.name')[0];
    },*/
    

    });

    consumes this JSON:

       {
      "album":{
         "covers":{
            "l":"http://media.audiobox.fm/images/albums/V3eQTPoJ/l.jpg?1318110127",
            "m":"http://media.audiobox.fm/images/albums/V3eQTPoJ/m.jpg?1318110127",
            "s":"http://media.audiobox.fm/images/albums/V3eQTPoJ/s.jpg?1318110127"
         },
         "artist":{
            "name":"New Order",
            "token":"OyOZqwkN"
         },
         "name":"(The Best Of)",
         "token":"V3eQTPoJ"
      }
    

    },


提交回复
热议问题