1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    10
    Vote Rating
    1
    junksh3d@gmail.com is on a distinguished road

      0  

    Default Basics; parsing multiple sets of data from one json store

    Basics; parsing multiple sets of data from one json store


    I'm starting out testing SA for an app we're building. I made a simple little REST server that sends json from our db.

    We are using this in the context of clients. I figured that it'd make sense to return all the relevant data for a client in one request as opposed to making a request for each separate group of data the client has.

    The json looks something like this:

    Code:
    {    "client": {
            "0": {
                "id": "12345",
                "type_id": "3",
                "association_id": "0",
                "is_active": "1",
                "manager_id": "2",
                "business_name": null,
                "has_payroll": "0",
                "business_proprietor_contact_id": null,
                "date_created": "1358893243",
                "date_modified": "1358893243"
            },
            "contacts": [
                {
                    "id": "1",
                    "client_id": "12345",
                    "contact_id": "1",
                    "is_primary": "0",
                    "display_priority": "0",
                    "relationship": "Client",
                    "friendly_name": "Homer",
                    "contact": [
                        {
                            "id": "1",
                            "surname": "Mr.",
                            "first_name": "Homer",
                            "middle_name": "J",
                            "last_name": "Simpson",
                            "client_id": "12345",
                            "date_created": "1356038714",
                            "date_modified": null
                        },
                        {
                            "addresses": [
                                {
                                    "id": "1",
                                    "contact_id": "1",
                                    "address_id": "16",
                                    "is_mailing_address": "0",
                                    "is_primary_address": "0",
                                    "display_priority": "0",
                                    "address": {
                                        "0": {
                                            "id": "16",
                                            "address": "5 Dirt Rd",
                                            "address2": "",
                                            "city": "TAXMASTER",
                                            "state": "NY",
                                            "zip_code": "454545",
                                            "country": "USA",
                                            "other": null,
                                            "phone": null,
                                            "fax": null,
                                            "display_priority": null,
                                            "is_mailing_address": "1"
                                        },
                                        "data": [
                                            {
                                                "id": "10",
                                                "label": "Phone",
                                                "value": "BUT WHO WAS",
                                                "date_created": "1356104685",
                                                "date_modified": "1357142782",
                                                "user_id": null,
                                                "display_priority": null,
                                                "client_id": null,
                                                "contact_id": null,
                                                "account_id": null,
                                                "business_id": null,
                                                "address_id": "16",
                                                "is_deleHomer": "0"
                                            },
                                            {
                                                "id": "14",
                                                "label": "Fax",
                                                "value": "simile",
                                                "date_created": "1356557379",
                                                "date_modified": "1357142782",
                                                "user_id": null,
                                                "display_priority": null,
                                                "client_id": null,
                                                "contact_id": null,
                                                "account_id": null,
                                                "business_id": null,
                                                "address_id": "16",
                                                "is_deleHomer": "0"
                                            },
                                            {
                                                "id": "17",
                                                "label": "Also Known as:",
                                                "value": "DUDE",
                                                "date_created": "1357141357",
                                                "date_modified": "1357142782",
                                                "user_id": null,
                                                "display_priority": null,
                                                "client_id": null,
                                                "contact_id": null,
                                                "account_id": null,
                                                "business_id": null,
                                                "address_id": "16",
                                                "is_deleHomer": "0"
                                            }
                                        ]
                                    }
                                },
                                {
                                    "id": "6",
                                    "contact_id": "1",
                                    "address_id": "26",
                                    "is_mailing_address": "0",
                                    "is_primary_address": "0",
                                    "display_priority": "0",
                                    "address": {
                                        "0": {
                                            "id": "26",
                                            "address": "1 Lift Road",
                                            "address2": "",
                                            "city": "Tony Beach",
                                            "state": "KS",
                                            "zip_code": "15151",
                                            "country": "USA",
                                            "other": null,
                                            "phone": null,
                                            "fax": null,
                                            "display_priority": null,
                                            "is_mailing_address": "0"
                                        },
                                        "data": [
                                            {
                                                "id": "18",
                                                "label": "Phone:",
                                                "value": "cool phone number",
                                                "date_created": "1357141527",
                                                "date_modified": "1357141527",
                                                "user_id": null,
                                                "display_priority": null,
                                                "client_id": null,
                                                "contact_id": null,
                                                "account_id": null,
                                                "business_id": null,
                                                "address_id": "26",
                                                "is_deleHomer": "0"
                                            },
                                            {
                                                "id": "19",
                                                "label": "Note:",
                                                "value": "cool note",
                                                "date_created": "1357141527",
                                                "date_modified": "1357141527",
                                                "user_id": null,
                                                "display_priority": null,
                                                "client_id": null,
                                                "contact_id": null,
                                                "account_id": null,
                                                "business_id": null,
                                                "address_id": "26",
                                                "is_deleHomer": "0"
                                            }
                                        ]
                                    }
                                },
                            ],
                            "data": [
                                {
                                    "id": "1",
                                    "label": "asdf",
                                    "value": "dfdfefefefef",
                                    "date_created": "1356038714",
                                    "date_modified": "1356040822",
                                    "user_id": "2",
                                    "display_priority": "0",
                                    "client_id": null,
                                    "contact_id": "1",
                                    "account_id": null,
                                    "business_id": null,
                                    "address_id": null,
                                    "is_deleHomer": "0"
                                },
                                {
                                    "id": "2",
                                    "label": "asfd",
                                    "value": "152151",
                                    "date_created": "1356038714",
                                    "date_modified": "1356040822",
                                    "user_id": null,
                                    "display_priority": "2",
                                    "client_id": null,
                                    "contact_id": "1",
                                    "account_id": null,
                                    "business_id": null,
                                    "address_id": null,
                                    "is_deleHomer": "0"
                                },
                            ]
                        }
                    ]
                },
                {
                    "id": "7",
                    "client_id": "12345",
                    "contact_id": "11",
                    "is_primary": "0",
                    "display_priority": "0",
                    "relationship": "None",
                    "friendly_name": "Mary Jane",
                    "contact": {
                        "0": {
                            "id": "11",
                            "surname": "",
                            "first_name": "Mary Jane",
                            "middle_name": "",
                            "last_name": "Simpson",
                            "client_id": null,
                            "date_created": "1357145795",
                            "date_modified": null
                        },
                        "7": {
                            "addresses": [
                                {
                                    "id": "11",
                                    "contact_id": "11",
                                    "address_id": "33",
                                    "is_mailing_address": "0",
                                    "is_primary_address": "0",
                                    "display_priority": "0",
                                    "address": {
                                        "0": {
                                            "id": "33",
                                            "address": "33 Street",
                                            "address2": "",
                                            "city": "NY",
                                            "state": "NY",
                                            "zip_code": "06830",
                                            "country": "USA",
                                            "other": null,
                                            "phone": null,
                                            "fax": null,
                                            "display_priority": null,
                                            "is_mailing_address": "0"
                                        },
                                        "data": [
                                            {
                                                "id": "31",
                                                "label": "Fax:",
                                                "value": "asdfasdf",
                                                "date_created": "1357145905",
                                                "date_modified": "1357145939",
                                                "user_id": null,
                                                "display_priority": null,
                                                "client_id": null,
                                                "contact_id": null,
                                                "account_id": null,
                                                "business_id": null,
                                                "address_id": "33",
                                                "is_deleHomer": "0"
                                            },
                                            {
                                                "id": "32",
                                                "label": "Fax:",
                                                "value": "sadfsadf",
                                                "date_created": "1357145905",
                                                "date_modified": "1357145905",
                                                "user_id": null,
                                                "display_priority": null,
                                                "client_id": null,
                                                "contact_id": null,
                                                "account_id": null,
                                                "business_id": null,
                                                "address_id": "33",
                                                "is_deleHomer": "0"
                                            }
                                        ]
                                    }
                                }
                            ],
                            "data": [
                                {
                                    "id": "29",
                                    "label": "Phone:",
                                    "value": "asdfsadf",
                                    "date_created": "1357145833",
                                    "date_modified": "1357145833",
                                    "user_id": "2",
                                    "display_priority": null,
                                    "client_id": null,
                                    "contact_id": "11",
                                    "account_id": null,
                                    "business_id": null,
                                    "address_id": null,
                                    "is_deleHomer": "0"
                                },
                                {
                                    "id": "30",
                                    "label": "Email:",
                                    "value": "dsfgdsfg",
                                    "date_created": "1357145855",
                                    "date_modified": "1357145855",
                                    "user_id": "2",
                                    "display_priority": null,
                                    "client_id": null,
                                    "contact_id": "11",
                                    "account_id": null,
                                    "business_id": null,
                                    "address_id": null,
                                    "is_deleHomer": "0"
                                }
                            ]
                        }
                    }
                }
            ],
            "notes": [
                {
                    "id": "5",
                    "client_id": "12345",
                    "label": "This is a HomerHomer Note",
                    "value": "This is from Homer's Dashboard Notes.",
                    "contact_id": null,
                    "address_id": null,
                    "account_id": null,
                    "account_data_id": null,
                    "account_credential_id": null,
                    "payment_id": null,
                    "contact_log_id": null,
                    "user_id": "2",
                    "bill_id": null,
                    "is_deleHomer": "0",
                    "date_created": "1357148256",
                    "date_modified": "1357148256"
                }
            ]
        }
    }
    I have a store for Clients and a model with id, is_active, contacts fields.

    I added a view and set the store to Clients. I can via tpl print the id, is_active. I cannot, however, get the contacts to show. If in the template I just add {contacts}, I get [object Object][object Object] but can't access anything inside those objects via contacts.contact.id or otherwise (btw, is there a sane way to log this object from tpl?)

    Can I, based on the json example, even do what I'm trying to do? i.e. can I grab a json response and split out the different groups within to separate components?

    Thanks.

  2. #2
    Sencha User
    Join Date
    Feb 2013
    Posts
    10
    Vote Rating
    1
    junksh3d@gmail.com is on a distinguished road

      0  

    Default


    Looks like this isn't natively available in extjs: http://stackoverflow.com/questions/8...-a-sub-element

    Can anyone confirm?

  3. #3
    Sencha Premium Member
    Join Date
    Nov 2007
    Location
    Moore, Oklahoma
    Posts
    464
    Vote Rating
    13
    Mthor will become famous soon enough

      0  

    Default


    what does your mapping look like in your model?

    I am guessing it would need to be mapping: 'client.contact'

  4. #4
    Sencha User
    Join Date
    Feb 2013
    Posts
    10
    Vote Rating
    1
    junksh3d@gmail.com is on a distinguished road

      0  

    Default


    Hi, thanks for the reply.

    Model:

    Code:
        Ext.define('MyApp.model.Client', {
            extend: 'Ext.data.Model',
    
    
            fields: [
                {
                    name: 'id'
                },
                {
                    name: 'last_name'
                },
                {
                    name: 'relationship'
                },
                {
                    name: 'contacts',
                    mapping: 'contacts[0]'
                },
                {
                    name: 'contact',
                    mapping: 'contacts[0].contact[0][0]'
                }
            ]
        });
    This works in that I can access the first item... Problem is iterating over the items and pulling out the detail.

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi