我无法运行外部库

时间:2017-04-03 16:52:43

标签: javascript json cordova ionic-framework

我有点困难。我相信这是因为我缺乏知识。事实上,我有一个外部库,可以使用外部硬件运行。该库是该硬件并运行一些事件。我无法理解如何在我的程序中运行此事件。按照我尝试使用的代码。

//An example of an implemented proxcard callback is as follows:
 grabba.proxcard.registerCallback(proxcardCallbacks, onError);
 var proxcardTimeoutFunction = function() {
     alert('Proxcard timed out');
 };
 var proxcardCallbacks = {
 //Functions may also be declared inline as seen here.
 triggeredEvent: function() {
     alert('Proxcard triggered');
 },
 //These functions are optional and unimplemented functions will simply not be called.
 //stoppedEvent : function () {
 //alert('Proxcard scanning stopped');
 //},
 scannedEvent: function(proxcard) {
 //proxcard contains data fields
 //Convert the data to a base 16 hex string
 var hexString = ons.grabba.util.integerArrayToHexString(proxcard.data);
     alert('Proxcard scanned event\n Data: ' + hexString + '\n' + "Type: " + proxcard.type);
 },
 //You may create a function separately as seen with proxcardTimeoutFunction here.
 timeoutEvent: proxcardTimeoutFunction
 };

我需要使用该硬件的RFID进行扫描。有关更多信息,请按照库的文档进行操作:

http://cordova.grabba.com/legacy/versions/v1.0.18/GrabbaProxcard.html

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

此示例不能正常工作,您必须使用自己的函数替换“proxcardCallbacks”和“onError”参数。

试试这个:

 <button onclick="grabba.proxcard.registerCallback({     //Functions may also be declared inline as seen here.
    triggeredEvent: function () {
        alert('Proxcard triggered');
    },
    //These functions are optional and unimplemented functions will simply not be called.
    //stoppedEvent : function () {
    //alert('Proxcard scanning stopped');
    //},
    scannedEvent: function (proxcard) {
        ////proxcard contains data fields
        ////Convert the data to a base 16 hex string
        try {
            //alert('data: ' + proxcard.data);
            var hexString = grabba.util.integerArrayToHexString(proxcard.data);
            alert('Proxcard scanned event\n Data: ' + hexString + '\n');
        } catch (err) {
            alert('catch error ' + err);
        }
    },
    timeoutEvent: function () {
        alert('Proxcard timed out');
    }
}, function (errorString) {
    alert('on error ' + errorString);
});">Scan</button>

PS:请注意我删除了“ons”。从“integerArrayToHexString”函数的乞讨。