1. #1
    Sencha Premium Member
    Join Date
    Jan 2013
    Posts
    118
    Answers
    8
    Vote Rating
    2
    vnggui is on a distinguished road

      0  

    Question Answered: convert function in model

    Answered: convert function in model


    I want to customize response data, insert port number to an URL string;

    In model define like:

    HTML Code:
    config: {
                 fields: [
                        {name:'nid', mapping:'ID'},
                        {name:'title', mapping:'title'},
                        {name:'imgurl',
                          mapping:'imgURL',                          
                          type:'string',
                          convert:function(v,rec){
                                var imgurlWithPort = imgurl.replace(/10.148.148.25/g,"10.148.148.25:8080")
                                return imgurlWithPort;
                          }
                        }
                    ]
        }
    error as 'imgurl undefined'.
    So how can customize mapping data (say, inserting a port number to URL string) using convert function?

    thanks

    gui

  2. post solution for those who have same concern:
    Assuming I have a property named 'imageUrlFromResponse' in response, like 'ID' and 'title', I can convert it like:
    HTML Code:
    config: {              fields: [                     {name:'nid', mapping:'ID'},                     {name:'title', mapping:'title'},                     {name:'imgurl',                                                 type:'string',                       convert:function(v,rec){
                                var imageUrl = rec.raw.imageUrlFromResponse;                             var imgurlWithPort = imageUrl.replace(/10.148.148.25/g,"10.148.148.25:8080")                             return imgurlWithPort;                       }                     }                 ]     }

  3. #2
    Sencha Premium Member
    Join Date
    Jan 2013
    Posts
    118
    Answers
    8
    Vote Rating
    2
    vnggui is on a distinguished road

      0  

    Default


    post solution for those who have same concern:
    Assuming I have a property named 'imageUrlFromResponse' in response, like 'ID' and 'title', I can convert it like:
    HTML Code:
    config: {              fields: [                     {name:'nid', mapping:'ID'},                     {name:'title', mapping:'title'},                     {name:'imgurl',                                                 type:'string',                       convert:function(v,rec){
                                var imageUrl = rec.raw.imageUrlFromResponse;                             var imgurlWithPort = imageUrl.replace(/10.148.148.25/g,"10.148.148.25:8080")                             return imgurlWithPort;                       }                     }                 ]     }