How to use ForEach to get value of the same property from array?

Hi
I’m not sure what terms to use but I think I need a foreach to get the value of subject and DisplayName.
I need the data to be displayed like this:

 <tr>
                    <td><input type="checkbox"></td>
                    <td class="mailbox-star"><a href="#"><i class="fa fa-star text-yellow"></i></a></td>
                    <td class="mailbox-name"><a href="read-mail.html">//DISPLAYNAME HERE</a></td>
                    <td class="mailbox-subject"><b id="sub">//SUBJECT HERE</b>
                    </td>
                    <td class="mailbox-attachment"><i class="fa fa-paperclip"></i></td>
                    <td class="mailbox-date">15 days ago</td>
                  </tr>

And then for every object the same thing but with the next subject value and so on.
Hopefully I’m been clear :grinning:
Here is a sample of the data:

{Action: "MessagesGetList", AccountID: 1,…}
@Time
:
1.7118399143219
AccountID
:
1
Action
:
"MessagesGetList"
Result
:
{@Object: "Collection/MessageCollection", @Count: 2,…}
@Collection
:
[{@Object: "Object/MessageListItem", Folder: "INBOX", Uid: 193,…},…]
0
:
{@Object: "Object/MessageListItem", Folder: "INBOX", Uid: 193,…}
@Object
:
"Object/MessageListItem"
Bcc
:
null
Cc
:
null
Custom
:
[]
DraftInfo
:
null
Folder
:
"INBOX"
From
:
[{@Object: "Object/Email", DisplayName: "Google", Email: "no-reply@accounts.google.com"}]
0
:
{@Object: "Object/Email", DisplayName: "Google", Email: "no-reply@accounts.google.com"}
@Object
:
"Object/Email"
DisplayName
:
"Google"
Email
:
"no-reply@accounts.google.com"
HasAttachments
:
false
HasIcalAttachment
:
false
HasVcardAttachment
:
false
Hash
:
"SbFqaKvKsXqao_t12jAQzY-ZaH4uHJrHU4ach7ry1s7Ml1NmYHVTMYDu0NrvUv8sQ7sxKelpw9dufpFDinVsv6CSI8lr3WSa01hqhdBfXHPGVS15aEkrncPyFzuLst8fdJIrofrmgMtD_4X2ybpFcXQPdT-D7pxPuYCIi6QUeHYcTpdIPLfSVmLo95jjnq2pn63SOSyRIfu_6YGNChM2gVXMngrcV5Ni6blHq7QjwYrh4UU24QtTxg.."
InternalTimeStampInUTC
:
1489786828
IsAnswered
:
false
IsFlagged
:
false
IsForwarded
:
false
IsSeen
:
true
MessageId
:
"<dNMSJ86OnC9WyI9i_Wd_lw@notifications.google.com>"
Priority
:
3
ReceivedOrDateTimeStampInUTC
:
1489786821
ReplyTo
:
null
Sender
:
null
Sensitivity
:
0
Size
:
10228
Subject
:
"Access for less secure apps has been turned on"
TextSize
:
2134
Threads
:
[]
TimeStampInUTC
:
1489786828
To
:
[{@Object: "Object/Email", DisplayName: "", Email: "abdullahseba@gmail.com"}]
0
:
{@Object: "Object/Email", DisplayName: "", Email: "abdullahseba@gmail.com"}
@Object
:
"Object/Email"
DisplayName
:
""
Email
:
"abdullahseba@gmail.com"
TrimmedTextSize
:
2134
Uid
:
193
1
:
{@Object: "Object/MessageListItem", Folder: "INBOX", Uid: 192,…}
@Object
:
"Object/MessageListItem"
Bcc
:
null
Cc
:
null
Custom
:
[]
DraftInfo
:
null
Folder
:
"INBOX"
From
:
[{@Object: "Object/Email", DisplayName: "Google", Email: "no-reply@accounts.google.com"}]
0
:
{@Object: "Object/Email", DisplayName: "Google", Email: "no-reply@accounts.google.com"}
@Object
:
"Object/Email"
DisplayName
:
"Google"
Email
:
"no-reply@accounts.google.com"
HasAttachments
:
false
HasIcalAttachment
:
false
HasVcardAttachment
:
false
Hash
:
"WDTXjIq5rbMXn63139YVoaCw8SBU7rn7kKUSp1fviMuY5g5ibpbab4tX7qvImPaEEoOkHBbEufwY6-_P8IFqf-W4crsByY8Hp-aPcC_W9klPVw1v_OHeiLWD_85j3Spkxo8SDVeN4rCN6iOtKVdNq_Lrih5tl0ssZjD9vJ9EZM6NFmA8m7TNloT3u_PTQY3LtiA4qvUtUM_l6uAuerOxhRdN2G4SnC0v"
InternalTimeStampInUTC
:
1489765381
IsAnswered
:
false
IsFlagged
:
false
IsForwarded
:
false
IsSeen
:
false
MessageId
:
"<rAGxZQD1HW9C53bkh7MNFg@notifications.google.com>"
Priority
:
3
ReceivedOrDateTimeStampInUTC
:
1489765373
ReplyTo
:
null
Sender
:
null
Sensitivity
:
0
Size
:
12152
Subject
:
"Review blocked sign-in attempt"
TextSize
:
2697
Threads
:
[]
TimeStampInUTC
:
1489765381
To
:
[{@Object: "Object/Email", DisplayName: "", Email: "abdullahseba@gmail.com"}]
0
:
{@Object: "Object/Email", DisplayName: "", Email: "abdullahseba@gmail.com"}
@Object
:
"Object/Email"
DisplayName
:
""
Email
:
"abdullahseba@gmail.com"
TrimmedTextSize
:
2697
Uid
:
192
@Count
:
2
@Object
:
"Collection/MessageCollection"
Filters
:
""
FolderHash
:
"60ecc4ac7509d7f57e5929493dbd1d56"
FolderName
:
"INBOX"
Limit
:
2
MessageCount
:
165
MessageResultCount
:
165
MessageUnseenCount
:
1
New
:
[]
Offset
:
0
Search
:
""
UidNext
:
"194"
Uids
:
[193, 192]
0
:
193
1
:
192

Thanks In advance.

that object example looks like it would cause a JS parser error.

Its whats returned by my mail API.

Which language do you use the API with?

Javascript:

$.ajax({
  type: "POST",
  url: "http://192.168.1.146/webmail/?/Ajax/",
  data: "Action=MessagesGetList&Folder=INBOX&Offset=0&Limit=2&Search=&Filters=&UseThreads=1&AccountID=1&Token=4ca3435dc07bfdcf3c82919ed270b872",
  crossDomain: true,
  dataType: "application/x-www-form-urlencodedon"
});

And it returns whats in original post

What do you get when you do a console.log() on the AJAX response?

your dataType should be "json", not a HTML form.

The oringnal post shows the same as what console.log shows
The api docs say use dataType: "application/x-www-form-urlencodedon" but I do actually use json cuz otherwise I have to use .fail!

.done(function( data ) {
	console.log(data); 
  });

But even with json var json = JSON.parse(data); returns an error.
https://afterlogic.com/docs/webmail-lite/integration-and-development/web-api

for the request header! but jQuery’s dataType is a response processing declaration.

you should use a browser that displays that better. it’s hardly readable what you copied.

anyways, you work with that json object like any other object: value = object.property

I tried this data.Result.AuthToken but it returns an object not a string so no good for html and what about the forreach?
JSON.stringify(data.Result.AuthToken) returns a string but with " so "a087d9a5d60533f308b7129e1212eb09"
What I copied was from chorme

judging from your screenshot it should return undefined as I can’t see AuthToken anywhere.

The paste-in went horribly wrong. as you can see when you compare it to the screenshot.

No, not this one but the login request. But makes no difference you still get "Google" for example. What I need is something that Repeats the html with the next object value as I said in the first post.

you would use .forEach() on your data source array (that you want to loop over), clone the table row, walk through the DOM tree inside the cloned row, set the new values, and attach the row to the table.

Note that there must be no IDs inside the row to clone.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.