Results 1 to 3 of 3

Thread: Store model and Association with a JSON Map

  1. #1
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    37
    Vote Rating
    0
      0  

    Exclamation Unanswered: Store model and Association with a JSON Map

    Hello,

    I have been wondering how can I associate this data:

    Code:
    rows: [
                    {
                        customerId: 1,
                        customerName: 'customer1',
                        forecasts: {
                            'Y1': {
                                currentValue: 1,
                                currentPercent: 99
                            },
                            'Y2': {
                                currentValue: 1,
                                currentPercent: 99
                            }, etc
                        }
                    }, etc
    All I have for now is this and Im kinda stuck...

    Code:
    Ext.define('armed.model.Forecast',
    {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'currentValue'}, // ???? Probably not good...
            {name: 'currentPercent'} // ???? Probably not good...
        ]
    });
    
    Ext.define('app.model.Customer',
    {
        extend: 'Ext.data.Model',
        ...
        fields: [
            {name: 'customerId'},
            {name: 'customerName', type: 'string'}
        ],
        hasMany: [
            {
                name: 'forecasts',
                model: 'app.model.Forecast',
                associationKey: 'forecasts'
            }
        ]
    });
    Since forecasts is a map ('Y1', 'Y2', etc) of value generated by server, I cannot be sure exactly what will be these values.. No idea how to map this.

  2. #2
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    37
    Vote Rating
    0
      0  

    Default

    fixed some error in my example, still need help!

  3. #3
    Sencha User jdkhamba's Avatar
    Join Date
    Jul 2012
    Posts
    234
    Answers
    44
    Vote Rating
    22
      0  

    Default

    forecasts needs to be an array since it is a nested. So you need to convert that to an array:

    Code:
    var forecastArr =[];for(var prop in forecasts){forecastArr.push(forecasts[prop])}
    It would be even better if you would do it on the server and just present it in the way client expects it.

Similar Threads

  1. Replies: 2
    Last Post: 17 Aug 2014, 6:48 AM
  2. Children elements aren't show using nested json, Model and hasMany association.
    By dusoft in forum Sencha Architect 2.x: Help & Discussions
    Replies: 2
    Last Post: 18 Jul 2013, 11:33 AM
  3. association problem charging json in a model...
    By Dano_Cuba in forum Sencha Touch 2.x: Q&A
    Replies: 1
    Last Post: 1 Aug 2012, 1:02 PM
  4. Why is an Association applied to a Model and not a Store?
    By DonRul in forum Sencha Architect 2.x: Help & Discussions
    Replies: 2
    Last Post: 3 May 2012, 2:46 PM

Posting Permissions

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