Jquery mobile Phonegap本机通知-不需要的“;“可选”;参数保持可见
我已经开发了一个帮助函数,用于在phonegap中创建本机通知,除了一件事之外,它工作得很好。。。当我省略可选参数时,Jquery mobile Phonegap本机通知-不需要的“;“可选”;参数保持可见,jquery-mobile,cordova,phonegap-build,Jquery Mobile,Cordova,Phonegap Build,我已经开发了一个帮助函数,用于在phonegap中创建本机通知,除了一件事之外,它工作得很好。。。当我省略可选参数时,navigator.notification.prompt会添加自己的默认值,如“默认文本”或“提示消息” 现在,快速修复方法是插入一个非空字符串”,作为未定义的,null和空字符串”不起作用 有人知道这是错误还是故意的吗?或者我在助手功能中遗漏了什么?正如我所说,提示是有效的,并给出了结果和所有,它只是可选的参数在不使用时给出了蹩脚的默认值 代码如下: var Helper =
navigator.notification.prompt
会添加自己的默认值,如“默认文本”
或“提示消息”
现在,快速修复方法是插入一个非空字符串”
,作为未定义的,null
和空字符串”
不起作用
有人知道这是错误还是故意的吗?或者我在助手功能中遗漏了什么?正如我所说,提示是有效的,并给出了结果和所有,它只是可选的参数在不使用时给出了蹩脚的默认值
代码如下:
var Helper = { // Hilfs Klasse, mit diversen Funktionen
alert:function(message, callback, title, buttonName){ //Ruft im Browser ein standard "Alert" auf und in der App ein Natives "Alert"
if (!callback) callback = function () { };
if (navigator.notification !== undefined && navigator.notification.alert !== undefined) { // Prüfungs ob die native Funktion verfügbar ist.
navigator.notification.alert(
message,
callback,
title ? title : "Info",
buttonName);
}else{
setTimeout(function(){
window.alert(message);
callback();
},0);
}
},
//Ruft im Browser ein standard "confirm" auf und in der App ein Natives "confirm"
confirm:function(message, callback, title, buttonLabels){
if(navigator.notification !== undefined && navigator.notification.confirm !== undefined){ // Prüfungs ob die native Funktion verfügbar ist.
navigator.notification.confirm(
message,
callback,
title ? title : "Bestätigen",
buttonLabels ? buttonLabels : ["OK", "Abbrechen"]
);
}else{
setTimeout(function(){
callback(window.confirm(message) ? 1 : 2);
},0);
}
},
//Ruft im Browser ein standard "prompt" auf und in der App ein Natives "prompt"
prompt:function(message, callback, title, defaultValue, buttonLabels){
if(navigator.notification !== undefined && navigator.notification.prompt !== undefined){ // Prüfungs ob die native Funktion verfügbar ist.
navigator.notification.prompt(
message,
callback,
title,
buttonLabels ? buttonLabels : ["OK", "Abbrechen"],
defaultValue ? defaultValue : undefined);
}else{
setTimeout(function(){
var result = window.prompt(message, defaultValue);
callback({
buttonIndex: result !== null ? 1 : 2,
input1:result
});
callback();
},0);
}
}
};
function scanFunction() {
var deviceToAdd = null;
if (isMobileDevice()) {
cordova.plugins.barcodeScanner.scan(
function (result) {
deviceToAdd = result.text;
if (deviceToAdd != "") {
Helper.confirm(
("Gerät " + deviceToAdd + " hinzufügen?"),
onConfirmScan,
"Gerät hinzufügen"
);
}
else {
Helper.prompt(
" ",
onConfirmPrompt,
"Gerät manuell hinzufügen",
" "
)
}
},
function (error) {
Helper.alert("Fehler: " + error);
}
);
}
else {
deviceToAdd = prompt("Gerät hinzufügen");
if (deviceToAdd != null) {
Server.registerDevice(deviceToAdd, loadDevices);
}
}
}
在的通知插件中
当您查看提示的js代码时,您有:
prompt: function(message, resultCallback, title, buttonLabels, defaultText) {
var _message = (message || "Prompt message");
var _title = (title || "Prompt");
var _buttonLabels = (buttonLabels || ["OK","Cancel"]);
var _defaultText = (defaultText || "");
exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]);
},
您可能会对这一部分感兴趣:var | title=(title | |“Prompt”)代码>因为不能使用空字符串作为标题