PubNub channelGroup.forEach 不是函数
PubNub channelGroup.forEach is not a function
我正在与 PubNub 合作开发一个安全的消息传递系统,但我 运行 遇到了频道列表返回 'not a function error' 的问题。这是我的代码:
$(document).on("pageshow", "#vendorMessages", function(event, ui) {
var channelGroup = String(window.vendorID);
pubnub.subscribe({
channelGroups: channelGroup
})
pubnub.channelGroups.listChannels({
channelGroup: channelGroup
},
function (status, response) {
console.log("listing push channel for device")
response.channels.forEach( function (channel) {
console.log(channel)
})
response.channels.forEach( function (channel) {
var channelFormatted = String(channel).split("_");
var channelMember = channelFormatted[1];
var e = $("#channelResults");
e.append("<li onClick='loadChannel("+channel+")>"+channelFormatted+"</li>");
e.listview("refresh");
})
}
)
})
返回此错误:
Uncaught TypeError: channelGroups.forEach is not a function
at _class.adaptSubscribeChange (https://cdn.pubnub.com/sdk/javascript/pubnub.4.4.4.js:3392:22)
at HTMLDivElement.<anonymous> (http://www.weddingindustryinsider.com/www/index.html:504:10)
at HTMLDocument.dispatch (https://code.jquery.com/jquery-1.11.1.js:4641:9)
at HTMLDocument.elemData.handle (https://code.jquery.com/jquery-1.11.1.js:4309:28)
at Object.trigger (https://code.jquery.com/jquery-1.11.1.js:4550:12)
at HTMLDivElement.<anonymous> (https://code.jquery.com/jquery-1.11.1.js:5260:17)
at Function.each (https://code.jquery.com/jquery-1.11.1.js:383:23)
at jQuery.fn.init.each (https://code.jquery.com/jquery-1.11.1.js:136:17)
at jQuery.fn.init.trigger (https://code.jquery.com/jquery-1.11.1.js:5259:15)
at $.(anonymous function).(anonymous function)._triggerWithDeprecated (https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js:5020:29)
如有任何帮助,我们将不胜感激。
我遇到了类似的问题。
问题是通道或通道组参数应该是一个数组。
替换:
var channelGroup = String(window.vendorID);
作者:
var channelGroup = [String(window.vendorID)];
我正在与 PubNub 合作开发一个安全的消息传递系统,但我 运行 遇到了频道列表返回 'not a function error' 的问题。这是我的代码:
$(document).on("pageshow", "#vendorMessages", function(event, ui) {
var channelGroup = String(window.vendorID);
pubnub.subscribe({
channelGroups: channelGroup
})
pubnub.channelGroups.listChannels({
channelGroup: channelGroup
},
function (status, response) {
console.log("listing push channel for device")
response.channels.forEach( function (channel) {
console.log(channel)
})
response.channels.forEach( function (channel) {
var channelFormatted = String(channel).split("_");
var channelMember = channelFormatted[1];
var e = $("#channelResults");
e.append("<li onClick='loadChannel("+channel+")>"+channelFormatted+"</li>");
e.listview("refresh");
})
}
)
})
返回此错误:
Uncaught TypeError: channelGroups.forEach is not a function
at _class.adaptSubscribeChange (https://cdn.pubnub.com/sdk/javascript/pubnub.4.4.4.js:3392:22)
at HTMLDivElement.<anonymous> (http://www.weddingindustryinsider.com/www/index.html:504:10)
at HTMLDocument.dispatch (https://code.jquery.com/jquery-1.11.1.js:4641:9)
at HTMLDocument.elemData.handle (https://code.jquery.com/jquery-1.11.1.js:4309:28)
at Object.trigger (https://code.jquery.com/jquery-1.11.1.js:4550:12)
at HTMLDivElement.<anonymous> (https://code.jquery.com/jquery-1.11.1.js:5260:17)
at Function.each (https://code.jquery.com/jquery-1.11.1.js:383:23)
at jQuery.fn.init.each (https://code.jquery.com/jquery-1.11.1.js:136:17)
at jQuery.fn.init.trigger (https://code.jquery.com/jquery-1.11.1.js:5259:15)
at $.(anonymous function).(anonymous function)._triggerWithDeprecated (https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js:5020:29)
如有任何帮助,我们将不胜感激。
我遇到了类似的问题。 问题是通道或通道组参数应该是一个数组。
替换:
var channelGroup = String(window.vendorID);
作者:
var channelGroup = [String(window.vendorID)];