简体   繁体   English

Laravel中的Pusher UI

[英]Pusher UI in laravel

I try to get my pusher notifications in dropdown in menu, not sure how to do that, here is my js code: 我尝试在菜单的下拉菜单中获取推送通知,但不确定如何执行操作,这是我的js代码:

<script type="text/javascript">
      var pusher = new Pusher('xxxxxxxxxxxxxx', {
        cluster: 'ap1',
        encrypted: true
      });

      var channel = pusher.subscribe('notify');
      channel.bind('notify-event', function(data) {
          alert(data.message);
      });
</script>

on alert i get my notification successfully, but what i'm looking for is to get them in html code below which is placed in my navbar: 收到警报后,我会成功收到通知,但是我要寻找的是将它们放入位于我的导航栏中的以下html代码中:

<a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#"><span class="label label-pill label-danger count"></span> <span class="glyphicon glyphicon-bell"></span></a>

<ul class="dropdown-menu">
</ul>

This is what is look like html code above : 这就是html code above

屏幕1

UPDATE 更新

I changed my js code to: 我将我的js代码更改为:

<script type="text/javascript">
      var pusher = new Pusher('xxxxxx', {
        cluster: 'ap1',
        encrypted: true
      });

      var channel = pusher.subscribe('notify');
      channel.bind('notify-event', function(data) {
        $.each(data, function(key, value) {
            $('#notifs').append('<li>'+ value + ' ' + value +'</li>');
            });
      });
<script>

and my html to: 和我的html到:

<ul class="dropdown-menu" id="notifs">
</ul>

Now I have result like: 现在我得到的结果是:

屏幕2

PS: I've tried $('#notifs').append('<li>'+ value['message'] + ' ' + value['name'] +'</li>'); }); PS:我已经尝试过$('#notifs').append('<li>'+ value['message'] + ' ' + value['name'] +'</li>'); }); $('#notifs').append('<li>'+ value['message'] + ' ' + value['name'] +'</li>'); }); but it returned undefined so i just used value and that's what i get. 但是它返回的是undefined所以我只用了value ,这就是我得到的。

SOLVED 解决了

I didn't need to foreach the result just needed to use data itself. 我不需要foreach结果,只需要使用data本身即可。

+ data.message + ' ' + data.name +

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM