【发布时间】:2021-09-04 17:29:49
【问题描述】:
我正在尝试在我的 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 语法?感谢您的帮助
控制器:
public function fetchcategory(){
$all_categories = HmsBbrCategory::all();
return response()->json([
'all_categories'=>$all_categories,
]);
}
【问题讨论】:
-
你能不能也显示控制器方法
-
添加了控制器@JohnLobo。这只是一个简单的表格获取
标签: sql ajax laravel if-statement append