gpt4 book ai didi

sql - Laravel ajax 在追加中使用 if 条件

转载 作者:行者123 更新时间:2023-12-04 07:28:55 26 4
gpt4 key购买 nike

我试图在我的 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 条件不显示我的表格列(无输出)。免责声明:表格已经连接,如果我取出 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 语法?谢谢你的帮助
Controller :
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;
}

关于sql - Laravel ajax 在追加中使用 if 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68061212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com