gpt4 book ai didi

Javascript Polymer - pubnub 回调函数

转载 作者:行者123 更新时间:2023-12-03 07:23:48 25 4
gpt4 key购买 nike

我有以下代码(在index.html中),它使用pubnub从服务器接收推送通知:

<html>
<head>
...
</head>
<body unresolved class="fullbleed layout vertical">
<template is="dom-bind">
<core-pubnub publish_key="xx" subscribe_key="xx">
<core-pubnub-publish id="pub" channel="todo" message="Test"> </core-pubnub-publish>
<core-pubnub-subscribe id="sub" channel="todo" messages="{{messages}}" presence="{{present}}" on-callback="{{subscribeCallback}}"></core-pubnub-subscribe>
</core-pubnub>
</template>
<script>
var scope = document.querySelector('template[is="dom-bind"]');
scope.subscribeCallback = function (e){
console.log("You got something...");
};
</script>
</body>
</html>

我想知道我是否成功收到来自服务器的通知,如 JavaScript 代码所示。我不确定这是否是正确的方法。在此感谢您的帮助。另外,如果我收到通知,我该如何阅读它(即访问 {{messages}})。

最佳答案

不要使用 {{}} 进行声明性事件处理程序绑定(bind)

on-callback="subscribeCallback"

关于Javascript Polymer - pubnub 回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36092019/

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