Getting nested array count.

Getting nested array count.

JohnJohnsonJohnJohnson Posts: 3Questions: 0Answers: 0
edited September 2016 in Free community support

I have the following AJAX.....

{
    "data": [{
        "Attachments": [],
        "Body": "Testing 12345",
        "Created": "\/Date(1454373660000-0500)\/",
        "FolderFrom": "Sent",
        "FolderTo": "Inbox",
        "Guid": "a9b8f7ad-f061-43e8-afcc-700a422a7c6c",
        "Id": 1,
        "StatusFrom": "SENT",
        "StatusIDFrom": 62,
        "StatusIDTo": 57,
        "StatusTo": "UNREAD",
        "Subject": "Test",
        "UserIDFrom": 1,
        "UserIDTo": 1,
        "UsernameFrom": "do0d",
        "UsernameTo": "do0d"
    }, {
        "Attachments": [],
        "Body": "Just a test email",
        "Created": "\/Date(1456953900000-0500)\/",
        "FolderFrom": "Sent",
        "FolderTo": "Inbox",
        "Guid": "5f497685-b8c0-455a-b7ef-36be1b444a17",
        "Id": 2,
        "StatusFrom": "SENT",
        "StatusIDFrom": 62,
        "StatusIDTo": 57,
        "StatusTo": "UNREAD",
        "Subject": "Testing",
        "UserIDFrom": 2,
        "UserIDTo": 1,
        "UsernameFrom": "t3st",
        "UsernameTo": "do0d"
    }]
}

and the following Javascript.....

                    {
                        "data": "attachments",
                        "class": "center",
                        "sortable": true,
                        "orderable": true,
                        "searchable": true,
                        "render": function (data, type, row) {
                            if (data.Attachments.count == 0)
                                return '';
                            else
                                return '<i tooltip="' + data.Attachments.count + ' Attachments" title="' + data.Attachments.count + ' Pictures Attached" class="fa fa-file-image-o text-primary"></i>';
                        }
                    },

It's blowing up on the Attachments.count. Ideas? Suggestions?

  • John

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Replies

  • JohnJohnsonJohnJohnson Posts: 3Questions: 0Answers: 0

    I forgot the column name was case-sensitive; however, it is still blowing up on .count. How can I get the count of the nested array?

  • JohnJohnsonJohnJohnson Posts: 3Questions: 0Answers: 0

    I tried .length too

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    There is no .count for arrays by default in Javascript - it should be .length.

    Moreover you have "data": "attachments", (which has a case error for the A) so the data property passed in to the rendering function is in fact the Attachments array - you would just use data.length.

    Allan

This discussion has been closed.