如何在 laravel 中显示多个 toast 通知
how to show multiple toast notifications in laravel
我正在尝试使用 toastr 显示多个通知,但只显示第一条消息。
return response()->json(array(
'status'=>'warning',
'message'=> 'Invoiced could not sent!',
'status'=>'success',
'message'=> 'item successfully modified!'
));
输出:
{ status: "success", message: "Booking successfully modified!" }
message: "Booking successfully modified!"
status: "success"
如果您能告诉我如何像上面的屏幕截图那样显示多条消息,我将不胜感激。有些通知可能处于警告状态,有些可能处于成功状态。
您的做法是覆盖数组的 status
和 message
属性。
考虑为这样的事情创建一个数组数组:
return response()->json(array(
'messages' => array(
array(
'status'=>'warning',
'message'=> 'Invoiced could not sent!'
),
array(
'status'=>'success',
'message'=> 'item successfully modified!'
)
)
));
然后你可以遍历每个元素。
$.ajax({
// Your current configuration
}).done(function (response) {
for(var msg in response.messages) {
var status = response.messages[msg]['status'];
var message = response.messages[msg]['message'];
toastr[status](message);
}
});
我正在尝试使用 toastr 显示多个通知,但只显示第一条消息。
return response()->json(array(
'status'=>'warning',
'message'=> 'Invoiced could not sent!',
'status'=>'success',
'message'=> 'item successfully modified!'
));
输出:
{ status: "success", message: "Booking successfully modified!" }
message: "Booking successfully modified!"
status: "success"
如果您能告诉我如何像上面的屏幕截图那样显示多条消息,我将不胜感激。有些通知可能处于警告状态,有些可能处于成功状态。
您的做法是覆盖数组的 status
和 message
属性。
考虑为这样的事情创建一个数组数组:
return response()->json(array(
'messages' => array(
array(
'status'=>'warning',
'message'=> 'Invoiced could not sent!'
),
array(
'status'=>'success',
'message'=> 'item successfully modified!'
)
)
));
然后你可以遍历每个元素。
$.ajax({
// Your current configuration
}).done(function (response) {
for(var msg in response.messages) {
var status = response.messages[msg]['status'];
var message = response.messages[msg]['message'];
toastr[status](message);
}
});