我正在编写一个使用quagga条码扫描器的cordova应用程序。 一切正常,条形码被正确识别,割炬开/关等。
当检测到条形码时,我在myDb中进行搜索。 如果找到条形码,则将打开一个弹出窗口以选择一些选项,然后将相关产品添加到购物车中(一切正常) 之后,开始新的扫描,依此类推。
问题是当找不到条形码时! 我尝试重新初始化该过程,但是连续扫描下一个条形码两次,三遍,四遍,就像同一过程有很多实例一样,App.lastResult被绕过,并且同一图像的许多副本显示在result_strip div
有什么方法可以销毁quagga.app并重新初始化?
function scan(e){ //***CREATE the page for the scanner
startScanner.idN=null;
var idN=e.data.param1;
//alert('scan idN'+idN);
$("#main").empty();
$("#main").append('');
//alert(idN);
if(idN!=='' ){
$("#main").append('<h1>COMBINE BARCODE</H1>');
}
else{
$("#main").append('<h1>SEARCH BARCODE</h1>');
}
$("#main").append('<section id="container" class="container"><div class="controls"><div class="ui-grid-solo" align="center"><a class="ui-link ui-btn-b ui-btn ui-icon-refresh ui-btn-icon-left ui-shadow ui-corner-all ui-btn-active stop" href="#" data-role="button" data-icon="icon-refresh" role="button" data-inline="true" id="riavvia">RIAVVIA</a></div><div class="ui-grid-solo" align="center"><fieldset class="reader-config-group"><input data-role="flipswitch" name="settings_torch" id="flip-checkbox-4" type="checkbox" ><label style=""><span>Luce</span></label></fieldset></div></div>');
$("#main").append('<div class="ui-grid-solo" align="center"><div id="result_strip"><ul class="thumbnails"></ul><ul class="collector"></ul></div><div id="interactive" class="viewport"></div></div></section>');
$("#main").appendTo( ".ui-page" ).trigger( "create" );
startScanner(idN);
}
function startScanner(idN){
var App = {
init : function() {
Quagga.init(this.state, function(err) {
if (err) {
console.log(err);
return;
}
App.attachListeners();
// App.checkCapabilities();
Quagga.start();
});
},
........
App.init();
....
Quagga.onDetected(function(result) {
var code = result.codeResult.code;
if (App.lastResult !== code) {
App.lastResult = code;
var $node = null, canvas = Quagga.canvas.dom.image;
$node = $('<li><div class="thumbnail"><div class="imgWrapper"><img /></div><div class="caption"><h4 class="code"></h4></div></div></li>');
$node.find("img").attr("src", canvas.toDataURL());
$node.find("h4.code").html(code);
console.log('IDN>>>>>'+idN+' BARCODE:>>'+code)
$("#result_strip ul.thumbnails").prepend($node);
navigator.notification.beep(1);
if(idN!==''){
//*****
//SEARCH BARCODE TO COMBINE WITH A PRODUCT
search_barcode(idN, code);
}
else {
//*******
//SEARCH FOR BARCODE TO ADD TO SHOPPING CART
myDB.transaction(function(transaction) {
var sql="select id as idN from wm_prodotti where barcode='"+code+"'";
console.log('barcode sql>'+sql);
transaction.executeSql(sql, [], function (tx, XX) {
var len = XX.rows.length
if(len>0){
var idN=XX.rows.item(0).idN;
console.log('trovato barcode'+idN);
var evt = {
data : {
param1 : idN,
param2 :'scan'
}
}
aggiungi_pre(evt);//**POPUP TO ADD TO CART
}
else
{
alert('BARCODE NOT FOUND');
var evt = {
data : {
param1 : ''
}
}
scan(evt); //***TRY TO START OVER BUT PROBLEMS WITH NEXT SCANSIONS
}
}, errorHandler);
});
}
}
});
}