Laravel ajax 在追加中使用 if 条件

Laravel ajax use an if condition inside an append

我正在尝试在 laravel ajax:

的两列上输出 if 条件
                    $.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>');
                    });

我的 if 条件不显示我的 table 列(无输出)。免责声明:table 已经连接,如果我去掉 if 条件,列显示没有问题。

我也试过:

                            <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>\

正确的 if 语法是什么?感谢您的帮助

控制器:

public function fetchcategory(){
    $all_categories = HmsBbrCategory::all();
    return response()->json([
        'all_categories'=>$all_categories,
    ]);
}

您可以使用反引号 (`) 代替引号

$.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:
                <mark class="mark-orange">${getmark(item.config_view_type)}</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>`);
});

function getmark(type) {
    var mark = '';
    if (type == 'P'){
        mark = 'Public'
    } else if (type == 'R'){
        mark = 'Restricted'
    }
    return mark;
}