Javascript Polymer - pubnub回调函数

时间:2016-03-18 18:40:27

标签: javascript html polymer pubnub

我有以下代码(在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}})。

1 个答案:

答案 0 :(得分:1)

不要将{{}}用于声明性事件处理程序绑定

on-callback="subscribeCallback"