1. #1
    Sencha User
    Join Date
    Feb 2012
    Location
    Noida,India
    Posts
    31
    Answers
    1
    Vote Rating
    1
    shruti_nair is on a distinguished road

      0  

    Default Unanswered: Error while using convert in Model

    Unanswered: Error while using convert in Model


    hi I'm trying to use convert config of field
    but get this error
    TypeError: 'undefined' is not an object (evaluating 'record.retailer.name')

    this is my model

    Code:
    function retailerDetail(v, record){
        return record.retailer.name + ', ' + record.retailer.retailerID+','+record.retailer.URL;
    }
    function locationDetail(v,record)
    {
        return record.location.line1+','+record.location.line2+','+record.location.city+','+record.location.postcode;
        
    }
    function vatDetail(v,record)
    {
        return record.vat.rate+','+record.vat.net+','+record.vat.vat+','+record.vat.gross;
    }
    Ext.regModel('receipts_model', {
        fields:[
        {name:'timestamp',type:'auto'},
        {name:'receiptID',type:'auto'},
        {name:'Identifier',type:'auto'},
        {name:'retailer',convert:retailerDetail},
        {name:'name',mapping:'retailer.name'},
        {name:'retailerID',mapping:'retailer.retailerID'},
        {name:'URL',mapping:'retailer.URL'},
        {name:'transactionID',type:'auto'},
        {name:'postcode',type:'auto'},
        {name:'location',convert:locationDetail},
        {name:'line1',mapping:'location.line1'},
        {name:'line2',mappimg:'location.line2'},
        {name:'city',mapping:'location.city'},
        {name:'locationPostcode',mapping:'location.postcode'},
        {name:'total' ,type:'auto'},
        {name:'vat',convert:vatDetail},
        {name:'rate',mapping:'vat.rate'},
        {name:'net',mapping:'vat.net'},
        {name:'vatAmount',mapping:'vat.vat'},
        {name:'gross',mapping:'vat.gross'},
    
        ],
        associations:[
                           {type: 'hasMany', model: 'testItemModel'},
                        {type:'hasMany',model:'testOfferModel'}
                     ],
     
     });
    this is my store
    Code:
    LoginForm.receipts_store =new Ext.data.Store({
        model  : 'receipts_model',
        sorters: 'purchaseDate',
      
      data: [
            {timestamp: '15:32 15 October 2011', receiptID: '123451', Identifier:'9876543210',retailer:{name:'Marks and Spencers',retailerID:'770000000001',URL:'images/Morrisons Logo.jpg'},transactionID:'5487854241',postcode:"EC3V3NP",total:'52.78',vat:{rate:'20',net:'43.98',vat:'8.8',gross:'52.78'}},
           
            ] });
    the data for which i'm trying to create the model
    Code:
    [     {         "timestamp":"15:32 15 October 2011",         "receiptID":123451,         "identifier":9876543210,         "retailer":{             "name":"Marks and Spencers",             "retailerID":"770000000001",             "retailer_image_url":"http://paprless.com/770000000001/public.png"         },         "transactionID":5487854241,         "postcode":"EC3V3NP",         "location":{             "line1":"25 West 2nd Street",             "line2":"",             "city":"London",             "postcode":"EC3V3NP"         },         "item":[             {"name":"SCIENCE PUTTY",                 "qty":1,                 "amount":5},             {"name":"WNC STRAW MLW LPOP",                 "qty":1,                 "amount":0.79},             {"name":"RIDLEYS CLASSIC JOKE",                 "qty":1,                 "amount":7},             {"name":"BRUT CHAMPAGNE MAG",                 "qty":1,                 "amount":39.99}         ],         "total":52.78,         "vat":{             "rate":20,             "net":43.98,             "vat":8.8,             "gross":52.78},         "returns":[         ],         "offer":{             "offerID":555555,             "condition":"Buy One",             "reward":"Get One Free",             "creator":"Travis Perkins",             "status":"live",             "image_url":"http://paprless.com/offers/555555/smart.png"         }     }  ]
    i'm also not sure whether i'm using the convert config properly
    also i want to know how to map the values returned by the function

    please guide

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,227
    Answers
    3523
    Vote Rating
    859
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Does record.retailer amount to anything? Is v the argument you want to use?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread