pds*_*ler 6 cordova windows-phone-8 cordova-plugins windows-phone-8.1
我需要在基于cordova的Windows 8手机应用程序中创建并安装自定义的cordova插件.目前,应用程序中的按钮单击处理程序无法查看调用cordova.exec的js对象
该对象,调用cordova.exe的函数称为dlScanner它有一个函数,scanBarcode调用cordova.exec
点击处理程序是这样的:
$(document).ready(function () {
$('#cmdOne').click(function () {
dlScanner.scanBarcode(
function (results) {
alert(results);
}), function (err) {
alert(err);
}, 'lowercaseworld'
});
});
Run Code Online (Sandbox Code Playgroud)
错误消息是这样的:
TypeError: Cannot read property 'scanBarcode' of undefined
Run Code Online (Sandbox Code Playgroud)
上下文:我在这里找到了Microsoft插件生成器PluginGenerator .然后我在应用程序的config.xml文件中使用View Designer,在Visual Studio Community 2015中,将该插件安装到VS之前为我创建的通用cordova Windows 8手机应用程序中.
该插件安装过程将其放在app的config.xml文件中
<vs:plugin name="com.contoso.dlScanner" version="0.1.0" src="C:\Users\TestAndDemo\dlScanner" />
Run Code Online (Sandbox Code Playgroud)
在dlScanner目录(如上所述)中,有src和www目录以及plugin.xml文件
在那个plugin.xml文件是这样的:
<js-module src="www/dlScanner.js" name="dlScanner">
<clobbers target="dlScanner" />
</js-module>
<!-- wp8 -->
<platform name="wp8">
<config-file target="config.xml" parent="/*">
<feature name="dlScanner">
<param name="wp-package" value="dlScanner"/>
</feature>
</config-file>
<source-file src="src/wp/dlScanner.cs" />
Run Code Online (Sandbox Code Playgroud)
www/dlScanner.js文件包含以下内容:
var dlScanner = {
scanBarcode: function (successCallback, errorCallback, strInput) {
cordova.exec(successCallback, errorCallback, "dlScanner", "scanBarcode", [strInput]);
}
}
module.exports = dlScanner;
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能使点击处理程序看到dlScanner对象?
谢谢
尝试在 Cordova 初始化并deviceready发出事件后调用插件。请在此处查看有关此事件的更多信息:http://docs.phonegap.com/en/3.5.0/cordova_events_events.md.html#deviceready。
| 归档时间: |
|
| 查看次数: |
130 次 |
| 最近记录: |