通过 toastr 访问 FCM 参数

Accessing FCM parameters by toastr

我收到通过 FCM 收到的通知,格式如下 JSON:

    {
      "message":{
        "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
        "notification":{
          "title":"Portugal vs. Denmark",
          "body":"great match!"
        },
        "data" : {
          "Nick" : "Mario",
          "Room" : "PortugalVSDenmark"
        }
      }
    }

我可以使用 payload.notification.title 访问通知标题和 body,如我的以下代码所示。 但是我如何访问 data 部分中的其他参数?

// 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.Nickpayload.data.Room.

访问数据属性