Javascript 通过toastr访问FCM参数
我通过FCM收到以下JSON格式的通知:Javascript 通过toastr访问FCM参数,javascript,firebase,firebase-cloud-messaging,toastr,Javascript,Firebase,Firebase Cloud Messaging,Toastr,我通过FCM收到以下JSON格式的通知: { "message":{ "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "notification":{ "title":"Portugal vs. Denmark", "body":"great match!" }, "data" : { "
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
}
我可以使用payload.notification.title
访问通知标题和正文,如下代码所示。
但是我如何访问数据部分中的其他参数
// Handle incoming messages
messaging.onMessage(function(payload) {
console.log("Notification received: ", payload);
toastr["success"](payload.notification.body, payload.notification.title, {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-top-left",
"onclick": payload.notification.click_action, // I also tried removing this
"preventDuplicates": false,
"showDuration": 30000,
"hideDuration": 1000,
"timeOut": 0,
"extendedTimeOut": 0,
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
});
});
这都只是一个JSON对象,因此您可以使用payload.data.Nick
和payload.data.Room
payload.data.Nick
?