【发布时间】:2017-07-04 09:21:31
【问题描述】:
我通过推送器将事件推送到以下代码: 我没有从 alertDivNotification 获得预期的 html。
<!-- output -->
<div class="alert alert-danger alert-server" role="alert">Hello</div>
<!-- expected -->
<div class="alert alert-danger alert-server" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Moving Servers</strong> Hello
</div>
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
var alertDivNotification = $('<div class="alert alert-danger alert-server" role="alert"><button type="button" class="close" data-dismiss="alert">×</button><strong>Moving Servers</strong> message</div>');
alertDivNotification.html(data.message);
$('#alertDivContainer').prepend(alertDivNotification);
});
【问题讨论】:
-
会发生什么?您是否在事件处理程序中收到 Pusher 事件?您可以通过在
var alertDivNotification = ...上方添加一个日志行来检查。您也可以添加pusher.logToConsole = true;并向我们展示您的日志。 -
我还认为您的
.html(...)将删除您的 div 中的<button>和<strong>。这可能不是你想要的。 -
@jameshfisher 是的,推送事件被正确触发,html div 缺少元素。