javascript - 科尔多瓦应用程序中的警报功能返回 [object, Object]
问题描述
我正在尝试在我的科尔多瓦应用程序中使用科尔多瓦本地通知插件,它工作正常,但返回预定通知的功能在警报框中显示 [object, Object],这是我尝试过的
var callbackOpts = function(notifications) {
//.log(notifications);
navigator.notification.alert(notifications.length === 0 ? '- none -' : notifications.join(', '));
var count = notifications.length;
document.getElementById("reminderCount").innerHTML = count;
};
function getScheduled() {
cordova.plugins.notification.local.getScheduled(callbackOpts);
document.getElementById("reminderCount").innerHTML = count;
}
请帮忙 这是通知格式
cordova.plugins.notification.local.schedule({
id: btn.dataset.id,
title: btn.dataset.name,
text: "Your Bus Will Be At The Station In " + changedTime + " Minutes",
trigger: { in: btn.dataset.diff, unit: 'minute' },
sound: "file://js/when.mp3",
icon: "file://img/mmArtboard.png"
});
解决方案
那是因为当您alert()
在显示之前使用对象作为参数 调用时.toString()
,将在其上调用方法。
>>[{id: 1, title: hello}].toString()
"[object Object]"
如果要按原样显示对象,可以调用JSON.strignify(notifications)
它,以便将其转换为 js 对象的字符串表示形式。
如果你想只显示对象数组中的标题,你可以只提取标题并加入它们并显示它。
>>let notifications = [{ id: 1, title: "title-1"}, { id: 1, title: "title-2"} ]
>>notifications.map((notification)=> notification.title ).join(' , ')
"title-1 , title-2 "
推荐阅读
- php - 警告:array_column() 期望参数 1 为数组,在
- python - Plotly choropleth 在在线但不在离线模式下工作
- angular - 更新 Firebase 和 Angular 后获取“firebase.auth 不是函数”
- python - Deleting an element from a list of tuples and then calculating a total price based on elements within each tuple
- python-3.x - 如何区分物体曲率的两种不同类型的异常?
- python - TypeError:“DictWrapper”对象不可下标
- angular - httpclient中类型化Get的优势
- linux - 音频驱动程序基地址、DMA 和 IRQ
- php - 如何在while循环中调用函数
- unit-testing - Angular:ng测试运行但不执行测试用例