How to i display complex object from published API call?


#1

i have a published a data from and API call i want to display it in a template

this is the this collection i log in the console. in my server.
this is a response from an API i call in the published.

    I20150708-14:58:10.268(8)? { next: 'https://cloudalytics-api-phx.prod.jivehosted.com:443/analytics/v2/export/activity/lastday?startIndex=100&count=100',
    I20150708-14:58:10.268(8)?   itemsPerPage: 100,
    I20150708-14:58:10.268(8)?   totalCount: 153339,
    I20150708-14:58:10.268(8)?   currentPage: 1,
    I20150708-14:58:10.268(8)?   totalPages: 1534 }
    I20150708-14:58:10.292(8)? [ { name: 'ACTIVITY_LOGIN_USER',
    I20150708-14:58:10.292(8)?     timestamp: 1436338676545,
    I20150708-14:58:10.292(8)?     context: { web: [Object] },
    I20150708-14:58:10.293(8)?     payload: {},
    I20150708-14:58:10.293(8)?     actorID: 1,
    I20150708-14:58:10.293(8)?     actorType: 3,
    I20150708-14:58:10.293(8)?     activityType: 'Login',
    I20150708-14:58:10.293(8)?     actionObjectId: 1,
    I20150708-14:58:10.293(8)?     actionObjectType: 3,
    I20150708-14:58:10.293(8)?     activity: 
    I20150708-14:58:10.293(8)?      { actor: [Object],
    I20150708-14:58:10.293(8)?        action: 'Login',
    I20150708-14:58:10.294(8)?        actionObject: [Object],
    I20150708-14:58:10.294(8)?        activityTime: 1436338676545 } }, ... etc]

in my router

data: function(){
        return Reports.find();
  },

in my template

{{paging.next}}

or

{{#each next}}
{{this}}
{{/each}} 

or

{{next}}

are not working

i also want to display the data of the 2nd object.

in my client when i log and fetch the data

[Object, Object]0: Object1: Objectlength: 2__proto__: Array[0]

the 1st Object is the paging details and the 2nd object is and Object of records witch contains the name, timestamp, context,activity, etc...

2nd question is. how would i query some data in mini mongo since there are only 2 object in the published data.

feel free to edit my post.


#2

Maybe {{#each this}}.


#3

hi steve, thanks for the reply

{{#each this}}
{{next}}
{{/each}}

is okay.

how about the 2nd object? hehe


#4

Well, your collection structure looks weird, to say the least. In order to parse this in a safe way, you would need either:

  • to use finOne instead of find and return typed objects from your data function
  • to use helpers and check object types

But I guess a quick hack to display your data is:

{{#each this}}
  {{next}}
  {{#each this}}
    {{this}}
  {{/each}}
{{/each}}

#5

yes, its from an API call which have several resource inside. and its really looks weird.

anyways i found another way to not to include some resource by explicit what resource you need. for example in my case i have this response:

which is the

  I20150708-14:58:10.268(8)? { next: 'https://cloudalytics-api-phx.prod.jivehosted.com:443/analytics/v2/export/activity/lastday?startIndex=100&count=100',
    I20150708-14:58:10.268(8)?   itemsPerPage: 100,
    I20150708-14:58:10.268(8)?   totalCount: 153339,
    I20150708-14:58:10.268(8)?   currentPage: 1,
    I20150708-14:58:10.268(8)?   totalPages: 1534 }

response.data.list, response.data.paging, response.data.header … etc… is the sample response my call when publishing it try to explicit the resources that you need.

var self=this;   
 var res = HTTP.get(api, {
                 headers: {
                     Authorization: token
                 }
        });
    	    _.each(res.data.list, function(item) {
          self.added('reports', Random.id(), item);
        });

so theres no way the other resources is included when you subscribe.

i apologize if its not clear. im bad at explaining.

feel free to edit. thanks!