Results 1 to 3 of 3

Thread: Sencha Touch belongsTo association using Store on Datalist

  1. #1
    Sencha User
    Join Date
    Apr 2011
    Location
    Lahore, Pakistan
    Posts
    5
    Vote Rating
    0
      0  

    Default Unanswered: Sencha Touch belongsTo association using Store on Datalist

    I want to get belongsTo record on datalist and show parent record fields.




    Ext.define('MyApp.model.Customer', {
    extend: 'Ext.data.Model',


    config: {
    fields: ['Id',
    'EMail'],
    hasMany: [{
    model: 'MyApp.model.OutstandingInvoice',
    name: 'OutstandingInvoice',
    primaryKey: 'Id',
    foreignKey: 'customerId',
    foreignStore: 'OutstandingInvoices'
    }]
    }
    });


    Ext.define('MyApp.model.OutstandingInvoice', {
    extend: 'Ext.data.Model',


    config: {
    fields: [
    'InvoiceDate',
    'InvoiceID',
    'customerId'
    ],
    belongsTo: [{
    model: 'MyApp.model.Customer',
    name: 'Customer',
    primaryKey: 'Id',
    foreignKey: 'customerId',
    foreignStore: 'Customers'
    }]
    }
    });




    Ext.define('MyApp.store.OutstandingInvoices', {
    extend: 'Ext.data.Store',


    config: {
    model: 'MyApp.model.OutstandingInvoice',
    storeId: 'OutstandingInvoiceStore',
    proxy: {
    useDefaultXhrHeader: false,
    type: 'ajax',
    url : 'http://localhost/getOutstandingInvoices',
    reader: {
    type: 'json'
    }
    },
    autoLoad: false
    }
    });




    Ext.define('MyApp.store.Customers', {
    extend: 'Ext.data.Store',


    config: {
    model: 'MyApp.model.Customer',
    storeId: 'CustomerStore',
    proxy: {
    useDefaultXhrHeader: false,
    type: 'ajax',
    url : 'http://localhost/getCustJList',
    reader: {
    type: 'json'
    }
    },
    autoLoad: false,
    sorters: [{
    property : 'FName',
    direction: 'ASC'
    }]
    }
    });






    Ext.define('MyApp.view.OutstandingInvoices', {
    extend: 'Ext.Panel',
    xtype: 'outstandingInvoicesXType',
    config: {
    cls : 'invoiceSummaryCls',
    scrollable: 'vertical',
    items: [
    {
    xtype: 'titlebar',
    docked: 'top',
    title: 'Outstanding Invoices'
    },
    {
    xtype : 'list',
    scrollable: false,
    store: 'OutstandingInvoiceStore',
    cls : 'p10',
    itemTpl: [
    '<div>Invoice # {InvoiceID}</div>',
    '<div>{InvoiceDate}</div>',
    '<div>{Customer.Email}</div>', // I want to show Customer name here as its belongsTo Customer
    ],
    listeners: {
    itemtap:function (list, index, targe, rec, e, eOpts) {
    console.log(rec)
    }
    }
    }
    ]
    }


    });




    I want to show Customer name in datalist but having issue with association or Xtemplate
    I am getting this error


    Uncaught Error: [ERROR][Ext.XTemplate#apply] Cannot read property 'Email' of undefined




    Please help me out in this.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,326
    Answers
    3884
    Vote Rating
    1297
      0  

    Default

    The store is using the customer model so you have the Id and EMail fields there. Then you can get the hasMany data from the Customer model.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Location
    Lahore, Pakistan
    Posts
    5
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by mitchellsimoens View Post
    The store is using the customer model so you have the Id and EMail fields there. Then you can get the hasMany data from the Customer model.
    Can you please explain your answer, how can I use association in List?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •