Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8564457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:12:19+00:00 2026-06-11T17:12:19+00:00

Consider this JSON { stream: { posts: [{ post_id: 1, post_type: text, post_thumb: bla1,

  • 0

Consider this JSON

{
    "stream": {
        "posts": [{
            "post_id": "1",
            "post_type": "text",
            "post_thumb": "bla1",
            "comments": [{
                "comment_id": "7",
                "comment_text": "asd",
            },
            {
                "comment_id": "8",
                "comment_text": "sdf",
            }],
        }],
    }
}

and my Model

Ext.define('MyAppApp.model.Post', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            'post_id',
            'post_type',
            'post_thumb',
            'comments',
        ],
        proxy: {
            type: 'jsonp',
            url:  'http://MyApp.com/home/index_app',
            reader: {
                type:         'json',
                rootProperty: 'stream'
            }
        }
    }
});

The above correctly shows a list of posts in my view.
I added a controller to push a panel to show the full content of each post, which is working.

Controller

Ext.define('MyAppApp.controller.Main', {
    extend: 'Ext.app.Controller',

    config: {
        refs: {
            stream: 'homepanel'
        },
        control: {
            'homepanel list': {
                itemtap: 'showPost'
            }
        }
    },

    showPost: function(list, index, element, record) {

/////// begin code block that solved my problem

    var data     = record.get('comments');
    var comments = '';

    Ext.Array.each(data, function(item) {
        comments += [item.comment_text] + '<br />';
    });

/////// end 

        this.getStream().push({
            xtype: 'panel',
            html: [
                '<p>' + record.get('post_thumb') + '</p>',
                '<p>' + record.get('comments') + '</p>',
                comments     // added to output HTML
            ].join(''),
            scrollable: true,
            styleHtmlContent: true,
        });
    }
});

My trouble is with retrieving the data from comments, which are nested in the JSON.

With the above controller, I get

[object Object],[object Object]

in my view and in the console I can open those objects and see the entirety of my comments.

But how do I display them in the view? (eg, how do I display "comment_text"?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:12:20+00:00Added an answer on June 11, 2026 at 5:12 pm

    Well, they are no longer JSON as soon as they are in your model, they got deserialized to object. To display them you should use a XTemplate. If you already use a template within your view you can directly access the properties of the objects to to render them. Let me know if anything is still unclear.

    Why exactly do you render the content by yourself into html property? Is that cause of performance reasons? I am not that used to ST, therefore I ask. Anyway, build up a little helper function that will loop through the comment array and return is as more or less formatted string (this will be up to you, also the check that the array is at least a empty one and never null)

    var data = record.get('comments')
    function(data) {
        var result = '',
            len = data.length,
            i=0;
    
        for(;i<len;i++) {
            result += data[i]['comment_text'] +'<br />'
        }
    
        return result;
    }
    

    Here is a implementation into the origin function. I post this cause the use of Ext.Array.each is not recommend, because it executes a function for each element and functioncalls within loops should be spared.

    showPost: function(list, index, element, record) {
            var data     = record.get('comments');
    
            function fetchComments(data) {
                var result = '',
                    len = data.length,
                    i = 0;
    
                for(;i<len;i++) {
                    result += data[i]['comment_text'] + '<br />';
                }
    
                return result;
            }
    
            this.getStream().push({
                xtype: 'panel',
                html: [
                    '<p>' + record.get('post_thumb') + '</p>',
                    '<p>' + fetchComments(data) + '</p>'
                ].join(''),
                scrollable: true,
                styleHtmlContent: true,
            });
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing JSON that is contained in an HTML element. Consider this markup: <div
Consider this my json string, [{ Mat_id: 2, Mat_Name: Steel, Measurement: mm, Description: Steel
Consider this scenario: You want to send some data to the client in JSON
Consider this as my json string, {Table : [{userid : 11,name : KumarP,designation :
Consider that you get this JSON object: { id: 3, name: 'C' } How
Consider this code: enum { ERR_START, ERR_CANNOTOPENFILE, ERR_CANNOTCONNECT, ERR_CANNOTCONNECTWITH, ERR_CANNOTGETHOSTNAME, ERR_CANNOTSEND, }; char* ERR_MESSAGE[]
Consider this contrived, trivial example: var foo = new byte[] {246, 127}; var bar
Consider this (rather pointless) javascript code: function make_closure() { var x = 123, y
Consider this simple model: A base Location table: +-------------------------------+ | Locations | +-------------------------------+ |(PK)
Consider this template function: template<typename ReturnT> ReturnT foo(const std::function<ReturnT ()>& fun) { return fun();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.