【问题标题】:How to write if condition inside json+ajax + table如何在json + ajax + table中编写if条件
【发布时间】:2019-05-05 14:22:46
【问题描述】:

我在td 部分中写入if 条件时遇到问题

var output = "<table id=\"report\" class=\"hover\" style=\"white-space:nowrap;\">" +
                "<thead>" +
                "<tr>" +
                    "<th>Report Date</th>" +
                    "<th>Group Name</th>" +
                    "<th>Group Status</th>" +
                    "<th>Plan Name</th>" +
                    "<th>Plan Status</th>" +
                    "<th>DC</th>" +
                    "<th>CRA</th>" +
                    "<th>Suspended</th>" +
                    "<th>Year End</th>" +
                    "<th>Effective</th>" +
                    "<th>Run Out</th>" +
                    "<th>Employees</th>" +
                    "<th>Dependents</th>" +
                "</tr>" +
                "</thead>" +
                "<tbody>";
            for (var value in (data.queryset)) {

            output +=
            "<tr>" +
                "<td>" + data.queryset[value].generated_date + '</td>' +
                '<td>' + data.queryset[value].group_name + '</td>' +
                '<td>' + data.queryset[value].group_status + '</td>' +
                '<td>' + data.queryset[value].plan_name + '</td>' +
                '<td>' + data.queryset[value].plan_status + '</td>' +
                {#'<td>' + data.queryset[value].debit_card + '</td>' +#}

                '<td>' + if (data.queryset.debit_card === 1)
                {None}else if (data.queryset.debit_card === 2)
                {Rx } else (data.queryset.debit_card === 3)
                {Full} + '</td>' +

                '<td>' + data.queryset[value].cra + '</td>' +
                '<td>' + data.queryset[value].claims_suspended + '</td>' +
                '<td>' + data.queryset[value].year_end + '</td>' +
                '<td>' + data.queryset[value].effective_date + '</td>' +
                '<td>' + data.queryset[value].termination_run_out_days + '</td>' +
                '<td>' + data.queryset[value].count_of_Employees + '</td>' +
                '<td>' + data.queryset[value].count_of_Dependents + "</td>" +
            "</tr>";
            }
            output += "</tbody></table>";

            displayResources.html(output);

            displayResources.find('#report').DataTable(options);

            setTimeout(() => {
                $('#main-content').show();
                _this.html('Generate Report')
            }, 2000);
        },
        error: function(error){

【问题讨论】:

    标签: json ajax django datatable


    【解决方案1】:

    请检查:

    var output = "<table id=\"report\" class=\"hover\" style=\"white-space:nowrap;\">" +
                    "<thead>" +
                    "<tr>" +
                        "<th>Report Date</th>" +
                        "<th>Group Name</th>" +
                        "<th>Group Status</th>" +
                        "<th>Plan Name</th>" +
                        "<th>Plan Status</th>" +
                        "<th>DC</th>" +
                        "<th>CRA</th>" +
                        "<th>Suspended</th>" +
                        "<th>Year End</th>" +
                        "<th>Effective</th>" +
                        "<th>Run Out</th>" +
                        "<th>Employees</th>" +
                        "<th>Dependents</th>" +
                    "</tr>" +
                    "</thead>" +
                    "<tbody>";
                for (var value in (data.queryset)) {
    
                    if (data.queryset.debit_card === 1){
                        var debt_crd = 'None';
                    }else if (data.queryset.debit_card === 2){
                        var debt_crd = 'Rx';
                    }else if(data.queryset.debit_card === 3){
                        var debt_crd = 'Full';
                    }
    
                output +=
                "<tr>" +
                    "<td>" + data.queryset[value].generated_date + '</td>' +
                    '<td>' + data.queryset[value].group_name + '</td>' +
                    '<td>' + data.queryset[value].group_status + '</td>' +
                    '<td>' + data.queryset[value].plan_name + '</td>' +
                    '<td>' + data.queryset[value].plan_status + '</td>' +
                    '<td>' + debt_crd + '</td>' +
                    '<td>' + data.queryset[value].cra + '</td>' +
                    '<td>' + data.queryset[value].claims_suspended + '</td>' +
                    '<td>' + data.queryset[value].year_end + '</td>' +
                    '<td>' + data.queryset[value].effective_date + '</td>' +
                    '<td>' + data.queryset[value].termination_run_out_days + '</td>' +
                    '<td>' + data.queryset[value].count_of_Employees + '</td>' +
                    '<td>' + data.queryset[value].count_of_Dependents + "</td>" +
                "</tr>";
                }
                output += "</tbody></table>";
    
                displayResources.html(output);
    
                displayResources.find('#report').DataTable(options);
    
                setTimeout(() => {
                    $('#main-content').show();
                    _this.html('Generate Report')
                }, 2000);
            },
            error: function(error){
    

    【讨论】:

      猜你喜欢
      • 2011-12-23
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 2017-09-18
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      相关资源
      最近更新 更多