Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sencha Touch 2(Store returning partial information from JSON file.)

    Hello,

    I want my store to populate the view with this information
    Code:
      { 'ID': '1', 'QuestionType': 'FreeText', 'QuestionOptions': '', 'QuestionLabel': 'Did the headaches start after an accident, illness, or infection?', 'QuestionText': '', 'AnswerText': '' },
    from the JSON file, but the alert tells me that it only sees the data as [object, Object], [object, Object].

    Any suggestions on how I can get this information to appear properly?

    Thanks in advance.

    VIEW
    Code:
     
    Ext.define('MyApp.view.QuestionList', {    
    xtype: 'QuestionList',
        extend: 'Ext.List',
        config: {
            questions: null,
            scrollable: false,
            itemCls: 'questionListItem',
            itemTpl: '{Name}, {Questions}
    
    
        },
    
    
        initialize: function () {
            this.fetchData({
                fn: function () {
                    this.buildView();
                },
                scope: this
            });
    
    
            this.callParent();
        },
    
    
        fetchData: function (callback) {
            var store = Ext.create('MyApp.store.Questionaires', {
                listeners: {
                    load: function (store, records, successful, operation, eOpts) {
                        this.config.questions = records[0].data.Sections[0].Questions;
                        callback.fn.call(callback.scope || this);
                    },
                    scope: this
                }
            });
    
    
    
    
            callback.fn.call(callback.scope || this);
        },
    
    
        buildView: function () {
            this.setupData();
            this.setupHeader();
        },
    
    
        setupData: function () {
            alert(this.config.questions);
            this.data = this.config.questions;
        },
    
    
        setupHeader: function () {
            var header = {
                layout: 'hbox',
                items: [
                {
                    html:
                            '<div class="">' +
                                '<label class="">Questions</label>' +
                            '</div>',
                    flex: 1
                }
                ]
            };
    
    
            this.add(header);
        }
    })
    JSON
    Code:
    {
        'success': true,    
        'results': [
            { 'ID': '1', 'Name': 'Sample', 'Description': 'Sample', 'CreateDate': '05/01/2012', Sections: [
                { 'ID': '1', 'Title': 'Headache', Questions: [
                    { 'ID': '1', 'QuestionType': 'FreeText', 'QuestionOptions': '', 'QuestionLabel': 'Did the headaches start after an accident, illness, or infection?', 'QuestionText': '', 'AnswerText': '' },    
                    { 'ID': '2', 'QuestionType': 'FreeText', 'QuestionOptions': '', 'QuestionLabel': 'How long has the patient had these headaches?', 'QuestionText': '', 'AnswerText': '' },    
                ] },
                { 'ID': '2', 'Title': 'Fever', Questions: [
                    { 'ID': '1', 'QuestionType': '', 'QuestionOptions': '', 'QuestionLabel': '', 'QuestionText': '', 'AnswerText': '' },    
         
                ] },
                { 'ID': '3', 'Title': 'Vomitting', Questions: [
                    { 'ID': '1', 'QuestionType': '', 'QuestionOptions': '', 'QuestionLabel': '', 'QuestionText': '', 'AnswerText': '' },    
         
                ] },
                { 'ID': '4', 'Title': 'Chest Pains', Questions: [
                    { 'ID': '1', 'QuestionType': '', 'QuestionOptions': '', 'QuestionLabel': '', 'QuestionText': '', 'AnswerText': '' },    
         
                ] },
    
    
            ] },
      
        ]
    }
    MODELS
    Code:
    Ext.define('MedEz.model.QuestionaireSection', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                { name: 'ID', type: 'int' },
                { name: 'Title', type: 'string' },
                { name: 'Questions' }
            ],
    
            validations: [
          { type: 'presence', field: 'ID' },
          { type: 'length', field: 'ID', max: 10 },
          { type: 'presence', field: 'Title' },
         ],
    
            associations: [
                { type: 'hasMany', model: 'MedEz.model.Question', name: 'Questions', autoload: true }
            ]
        }
    Code:
      Ext.define('MedEz.model.Question', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                { name: 'ID', type: 'int' },
                { name: 'QuestionType', type: 'string' },
                { name: 'QuestionOptions', type: 'string' },
                { name: 'QuestionLabel', type: 'string' },
                { name: 'QuestionText', type: 'string' },
                { name: 'AnswerText', type: 'string' },
            ],
    
            validations: [
          { type: 'presence', field: 'ID' },
          { type: 'length', field: 'ID', max: 10 },
          { type: 'presence', field: 'QuestionType' },
          { type: 'presence', field: 'QuestionText' },
          { type: 'presence', field: 'AnswerText' },
         ]
        }
    });

  • #2
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I changed
    Code:
     alert(this.config.questions);
    to
    Code:
     console.log(this.config.questions);
    . The console showed that the objects had the information I need, but the information is still not displaying properly. Any suggestion on how I can get the Nested JSON objects to display?

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Same issue

    Hi.

    Did you ever get this fixed? I've run into the same issue.

    Any help would be greatly appreciated.


  •  

    Posting Permissions

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