dimanche 20 juin 2021

Laravel ajax use an if condition inside an append

I am trying to output an if condition on my two columns in my laravel ajax:

                    $.each(response.all_categories, function (key, item) {
                        $('tbody').append('<tr>\
                            <td><p class="font-weight-bold mb-0">'+item.category_name+'</p>'+item.category_description+'</td>\
                            <td>View:\
                                if ('+item.config_view_type+' == 'P'){\
                                <mark class="mark-orange">Public</mark>\
                                } elseif ('+item.config_view_type+' == 'R'){\
                                <mark class="mark-orange">Restricted</mark>}\
                            <br>Edit:\
                            </td>\
                            <td>View:\
                            </td>\
                            <td>\
                                <button type="button" value="'+item.category_id+'" class="btn btn-outline-secondary">\
                                <i class="fas fa-edit"></i> Edit</button><button type="button" value="'+item.category_id+'" class="btn btn-outline-secondary">\
                                <i class="fas fa-trash"></i> Delete</button>\
                            </td>\
                            </tr>');
                    });

my if condition about does not show my table columns (no output). Disclaimer: the table is already connected, columns are shown without issue if I take out the if condition.

I also tried:

                            <td>View:\
                                @if ('+item.config_view_type+' == 'P')\
                                <mark class="mark-orange">Public</mark>\
                                @elseif ('+item.config_edit_type+' == 'R')\
                                <mark class="mark-orange">Restricted</mark>\
                            @endif\ 
                            <br>Edit:\
                            </td>\

what is the correct if syntax for this? thanks for any help

Aucun commentaire:

Enregistrer un commentaire