Results 1 to 2 of 2

Thread: Reading complex JSON object into model/store (2.4.2)

  1. #1
    Sencha Premium User
    Join Date
    Oct 2015
    Location
    Grand Rapids, Michigan
    Posts
    8

    Default Reading complex JSON object into model/store (2.4.2)

    Hi Everyone,
    I'm working on reading a nested JSON object into a model in my app. I'm able to get the JSON object from the server, but I'm not sure how to go about creating my user object based on that.

    The structure of the JSON is as follows:
    Code:
    {
    "user": [
    {
    "PERSON": {
    "PERSON_KEY": "",
    "EMAIL_ADDR": "",
    "FIRST_NAME": "",
    "LAST_NAME": "",
    "CELL_PHONE_NBR": "",
    "BIRTHDAY_MONTH_NBR": "",
    "BIRTHDAY_DAY_NBR": ""
    },
    "HOUSEHOLD": {
    "STREET1_ADDR": "",
    "STREET2_ADDR": "",
    "CITY_NAME": "",
    "STATE_CD": "",
    "ZIP_CODE": ""
    }
    ...
    ]
    }
    each "user" object has exactly one "PERSON", one "HOUSEHOLD", etc. My model attempts to use a 'hasOne'/'belongsTo' relationship:
    Code:
    Ext.define('myApp.model.user', {
       extend: 'Ext.data.Model',
       config: {
          requires: [
             'Ext.data.Field'
          ],
          associations: [
             {
                type: 'hasOne',
                model: 'myApp.model.PERSON',
                autoLoad: true,
                associationKey: 'user.PERSON'
             },
    ...
    
    Ext.define('myApp.model.PERSON', {
       extend: 'Ext.data.Model',
    
       requires: [
          'Ext.data.Field'
       ],
    
       config: {
          belongsTo: 'myApp.model.user',
          fields: [
             {
                name: 'PERSON_KEY',
                type: 'string'
             },
    ...
    The store for the user object contains the proxy call (which appears to work correctly) and the following:
    Code:
          autoLoad: true,
          autoSync: true,
          model: 'yes.model.user',
          storeId: 'user'
    I've tried a number of things in the controller to load the object into the model, but I haven't had any luck so far. I'm sure there's a concept I'm misunderstanding here. I genuinely appreciate any help you folks are able to provide.

  2. #2
    Sencha User
    Join Date
    Jan 2016
    Posts
    462
    Answers
    60

    Default

    You should not need associations unless you are loading two different stores. It sounds like you are only getting one JSON response back? If so, you don't even need to define the model. If you do want to define the model, you may want to consider mapping: http://docs.sencha.com/touch/2.4/2.4...ld-cfg-mapping

Similar Threads

  1. Replies: 6
    Last Post: 15 Sep 2012, 4:34 AM
  2. Extjs reading complex JSON data into store
    By vijaykumarjoshi in forum Ext: Discussion
    Replies: 5
    Last Post: 21 Jun 2012, 9:35 AM
  3. [Noob Question] Send complex Object to JSON Store
    By Kurt001 in forum Sencha Touch 1.x: Discussion
    Replies: 3
    Last Post: 14 Jul 2011, 8:06 AM
  4. Reading complex JSON
    By john_tadros in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 31 Mar 2010, 3:18 PM
  5. Grid+Store reading JSON complex Data
    By WLiCPSC in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 10 Mar 2009, 11:16 AM

Posting Permissions

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