Phonegap条形码扫描仪:无法'我不能让它跑
Phonegap barcode scanner: couldn't make it run
我试图通过插件的基本安装创建一个默认的Phonegap条形码扫描仪,但效果不佳。我不知道发生了什么。这是我的代码:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
console.log('-');
console.log(cordova);
console.log('-');
console.log(cordova.plugins.barcodeScanner);
console.log('-');
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode'n" +
"Result: " + result.text + "'n" +
"Format: " + result.format + "'n" +
Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
}
);
}
};
它基本上是默认的Phonegap插件面板。问题是它无法识别cordova.plugin.barcodeScanner
。我已经通过Phonegap Windows工具创建了该项目,并在文件夹中运行了cordova plugin add cordova-plugin-statusbar
命令。请帮帮我,我看不到任何这样的代码示例。谢谢
您可以在javascript中调用getScanner()函数onClick事件Read More Here
function getScanner(){
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode'n" +
"Result: " + result.text + "'n" +
"Format: " + result.format + "'n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
}
); }
如果不起作用,请告诉我。。
相关文章:
- 不能从angular2中的子组件指定父组件中的数组
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- 转义符不能与innerHTML一起使用
- JSON.parse没有'不能使用Javascript
- JS可以在Chrome中工作,但不能在Firefox中工作
- 砌体不能填补小缺口
- javascript扫雷器floodfill算法不能正常工作
- JavaScript指令不能像我想象的那样工作
- 为什么在这个网站上不能通过JS访问元素
- Facebook登录按钮没有'不能在Firefox上工作
- WebRTC视频聊天可以在FF中使用,但不能在Chrome中使用
- 为什么jQuery 1.8不能在IE8和InternetExplorer9中使用?(截至2012年9月的IE9最新版本)
- AngularJS:$q.dedefe()不能由工厂方法共享
- 不能在同一页上进行多个jquery幻灯片切换
- 不能在图像中的地图标记中使用花式框jquery插件的区域标记
- jQuery Datepicker可以在Safari中工作,但不能在FF或Chrome中工作
- javascript没有´我不能在joomla 3.0中工作
- 在ES6中,模块将导致多个网络调用,因为两个模块不能在单个文件中定义
- Phonegap条形码扫描仪:无法'我不能让它跑