1

我已完成以下操作来安装和使用条形码扫描仪。

>phonegap plugin add https://github.com/jonathannaguin/BarcodeScanner

这成功地在 phonegap/plugins 目录中安装了条码扫描器插件。

然后我像这样为android构建它

phonegap build android

这也顺利完成了。然后我使用文本字段上的处理程序将其放置在 sencha 触摸应用程序中。但是,当该字段被点击时,没有结果。没发生什么事。

Ext.define("Tasks.view.BarcodeField", {
extend: 'Ext.Container',
alias:'widget.barcodeField',

xtype: 'barcodefield',

config: {    
    layout: 'hbox',
    id: 'barcodeField',
    itemId: 'barcodeField',
    items: [
        {
            xtype: 'textfield',
            label: 'Barcode',
            labelWidth: '37.4%',                            
            flex: 4        
        },
        {
            xtype: 'image',
            id : 'barcodeScanner',
            itemId : 'barcodeScanner',
            src: 'resources/images/barcodes.png',
            padding: '6 0 0 0',
            flex: 1,
            listeners: {
                tap: function() {
                    console.log("Starting the barcode Scanner");
                    function success(result) {
                         alert("We got a barcode\n" +
                        "Result: " + result.text + "\n" +
                        "Format: " + result.format + "\n" +
                        "Cancelled: " + result.cancelled);
                    }

                    function fail(error) {
                          alert("Scanning failed: " + error);
                    }

                     cordova.plugins.barcodeScanner.scan(success, fail);
                }
            }               
        }        
    ]        
},

getValue : function() 
{   
    console.log(this.getItems().getAt(0).getValue());
    return this.getItems().getAt(0).getValue();
},
setValue : function(newvalue) {
   this.getItems().getAt(0).setValue(newvalue);
}

});

我看到正在调用点击处理程序以及控制台上的日志语句。

4

1 回答 1

1

我有对条形码插件的调用,它正在工作。我没有调用cordova.plugins,而是使用了window.plugins,它可以工作。

Ext.define("Tasks.view.BarcodeField", {
extend: 'Ext.Container',
alias:'widget.barcodeField',

xtype: 'barcodefield',

config: {    
    layout: 'hbox',
    id: 'barcodeField',
    itemId: 'barcodeField',
    items: [
        {
            xtype: 'textfield',
            label: 'Barcode',
            labelWidth: '37.4%',                            
            flex: 4        
        },
        {
            xtype: 'image',
            id : 'barcodeScanner',
            itemId : 'barcodeScanner',
            src: 'resources/images/barcodes.png',
            padding: '6 0 0 0',
            flex: 1,
            listeners: {
                tap: function() {
                    console.log("Starting the barcode Scanner");
                    function success(result) {
                         alert("We got a barcode\n" +
                        "Result: " + result.text + "\n" +
                        "Format: " + result.format + "\n" +
                        "Cancelled: " + result.cancelled);
                    }

                    function fail(error) {
                          alert("Scanning failed: " + error);
                    }
                    window.plugins.barcodeScanner.scan(success, fail);
                    // cordova.plugins.barcodeScanner.scan(success, fail);
                }
            }               
        }        
    ]        
},

getValue : function() 
{   
    console.log(this.getItems().getAt(0).getValue());
    return this.getItems().getAt(0).getValue();
},
setValue : function(newvalue) {
   this.getItems().getAt(0).setValue(newvalue);
}

});

于 2014-03-11T17:10:52.360 回答