gpt4 book ai didi

javascript - 我的插件中的 Successcallback 和 Errorcallback

转载 作者:行者123 更新时间:2023-12-03 04:11:11 25 4
gpt4 key购买 nike

嗨,我目前正在尝试在我的插件中调用 Successcallback 和 Errorcallback。我使用 ionic v1 似乎它显示了所有成功和错误的控制台..

这是我使用的插件

var exec = require('cordova/exec');
var cordova = require('cordova');

var triangle = {

initialize: function(applicationId, accessKey, secretKey, successCallback, errorCallback) {
// Define document events used by the API
cordova.addDocumentEventHandler('ontaperror');
cordova.addDocumentEventHandler('ontapsuccess');
cordova.addDocumentEventHandler('ontapdetect');

// Call the Android side to initialize the Triangle session
exec(successCallback, errorCallback, "Triangle", "initialize", [applicationId, accessKey, secretKey]);
}
}

module.exports = triangle;

这是在我的 Controller 中调用成功和错误回调

document.addEventListener('deviceready', scanCreditCard, false);

function scanCreditCard() {

navigator.triangle.initialize(
"My Application ID", // application ID
"Access Key", // access key
"SecretKey", // secret key
succcessCallack(),
errorCallback()

);
};


function succcessCallack() {

console.log("Ready to scan")

// Subscribe to events that the Triangle APIs raise
document.addEventListener('ontaperror', onTapError(), false);
document.addEventListener('ontapdetect', onTapDetect(), false);
document.addEventListener('ontapsuccess', onNewCard(), false);


}

function errorCallback(message) {

console.log("there was an error initializing the Triangle APIs");
console.error(message);
alert("Error")

}

function onNewCard(card) {

console.log("Scanned card successfully.");

// Display basic card information to the user
// various other properties such as cardholderName,
// activationDate, expiryDate, cardPreferredName, and encryptedAccountNumber
// may be available.
var dataToShow = card.cardBrand;
if (card.cardholderName != undefined) {
dataToShow += "\n" + card.cardholderName;
}
dataToShow += "\n" + card.lastFourDigits;
alert(dataToShow);

}

function onTapDetect() {
console.log("Detected new tap.");

}


function onTapError(error) {

console.log("Error processing contactless card.");
console.error(error);
}

最佳答案

navigator.triangle.initialize(
"My Application ID",
"Access Key",
"SecretKey",
succcessCallack, // remove ()
errorCallback // remove ()
);

当您通过名称引用函数时,不需要包含括号。带括号意味着执行该函数并使用其返回值。

关于javascript - 我的插件中的 Successcallback 和 Errorcallback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44324797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com