0

I'm having trouble to display the data returned as JSON. It is undefined. How can I iterate a multidimensional array?

Here's the result of console.log(result.new_record); and below is the result in HTML.

enter image description here

Success code

success :   function(result)
            {
                var html = '';
                result = JSON.parse(result);
                console.log(result.new_record);
                $(result.new_record).each(function(index, data){

                    html += tbl_tag(data);
                });
                $(target).html(html);
                event_time_entry();
                //whole_time_check();
                remove_tag();
            }

the tbl_tag function

function tbl_tag(data)
    {
        var html = '<tr class="text-center time-record main">';
        html += '<td>' + data.payroll_employee_display_name  + ' <input type="hidden" name="employee_tag[]" value="'+data.payroll_leave_employee_id+'"></td>';
        html += '<td>'+ data.total_leave_consume +'</td>';
        html += '<td>'+ data.remaining_leave +'</td>';
    //  html += '<td class="text-center"><input type="checkbox" checked="checked" class="whole_day" name="whole_day_'+data.payroll_leave_employee_id+'" value="1"></td>';
        html += '<td class="text-center edit-data zerotogray" width="25%"><input type="text" name="leave_hours_'+data.payroll_leave_employee_id+'" placeholder="00:00" class="text-center form-control break time-entry time-target time-entry-24 is-timeEntry"></td>';
        html += '<td class="text-center"><a href="#" class="btn-remove-tag" data-content="'+data.payroll_employee_id+'"><i class="fa fa-times"></i></a></td>';
        html += '</tr>';
        return html;
    }
JJJ
  • 32,902
  • 20
  • 89
  • 102
hihihihi
  • 68
  • 1
  • 5
  • 29

1 Answers1

1

Passing data[0] to tbl_tag function would work assuming there will always be only one record in result.new_record in each iteration.