lundi 12 juillet 2021

if statement to change string within ajax call

I'm appending a list of rows that will have a different status depending on some booleans. The status displays on the list.

            $.ajax({
                type: "GET",
                url: "@Url.Action("Users", "Api/Request")",
                data: "{}",
                success: function (readyUsers) {
                    var row = "";
                    status = "";

                    for (var i = 0; i < readyUsers.length; i++) {
                        if (readyUsers[i].ManagerCompleted == true) {
                            status = "Waiting for HR approval";
                        }
                        else if (readyUsers[i].HRReject == true) {
                            status = "Requires ammendments";
                        };
                        row = $("<tr/>");
                        row.append("<td>" + readyUsers[i].Ref + "</td>");
                        row.append("<td>" + readyUsers[i].Surname + ", " + readyUsers[i].FirstName + "</td>");
                        row.append("<td>" + readyUsers[i].Department + "</td>");
                        row.append("<td>" + readyUsers[i].StartDate + "</td>");
                        row.append("<td>" + status + "</td>");
                        $("#userTable").append(row);
                    };
                }
            });

This is how I would think it should work, yet it's displaying 'Waiting for HR approval' for all of them when I know they shouldn't be.

Can you please point out where I'm going wrong here?

Aucun commentaire:

Enregistrer un commentaire