如何从 html (webview-ext) 启动事件并在 nativescript 中捕获它们?
How to launch events from html (webview-ext) and catching them in nativescript?
我正在使用 webwiew-ext 并且我想从 webview-ext 表单启动事件以获取数据并使用 nativescript 脚本 sqlite 保存它
这是我为测试事件所做的示例,但它不起作用:
我的 js 文件:
function callFromNativeScript() {
window.nsWebViewBridgee.emit("got", { huba: "hop" });
console.log("got a message from nativescript");
}
像 header 中那样加载到 html 文件中:
<script src="../js/index.js" type="text/javascript"></script>
我的 nativescript main.js 文件:
const Sqlite=require("nativescript-sqlite");
exports.pageLoaded =function(args ){
page = args.object;
var db_promise = new Sqlite("test.db", function(err,db) {
if (err) {
console.error("We failed to open database", err);
} else {
console.log("Is a Sqlite Database:", Sqlite.isSqlite(db) ? "Yes" : "No");
db.get('select * from test where id=1 ', [1], function(err, row) {
if(row){
console.log("Row of data was: ", row);
}else if(err)
{
console.log("les guignols");
} // Prints [["Field1", "Field2",...]]
});
// This should ALWAYS be true, db object is open in the "Callback" if no errors occurred
console.log("Are we open yet (Inside Callback)? ", db.isOpen() ? "Yes" : "No"); // Yes
}
});
window.nsWebViewBridge.on("got",function(message){
console.log("Salut"+message);
console.log("hello");
});
console.log("bonjour");
}
我的 xml 文件 file :
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" actionBarHidden="true" xmlns:nota="@nota/nativescript-webview-ext">
<nota:WebViewExt src="~/html/index.html"> </nota:WebViewExt> </Page>
它内置了在 webview 中执行代码的函数。
我正在使用 webwiew-ext 并且我想从 webview-ext 表单启动事件以获取数据并使用 nativescript 脚本 sqlite 保存它 这是我为测试事件所做的示例,但它不起作用: 我的 js 文件:
function callFromNativeScript() {
window.nsWebViewBridgee.emit("got", { huba: "hop" });
console.log("got a message from nativescript");
}
像 header 中那样加载到 html 文件中:
<script src="../js/index.js" type="text/javascript"></script>
我的 nativescript main.js 文件:
const Sqlite=require("nativescript-sqlite");
exports.pageLoaded =function(args ){
page = args.object;
var db_promise = new Sqlite("test.db", function(err,db) {
if (err) {
console.error("We failed to open database", err);
} else {
console.log("Is a Sqlite Database:", Sqlite.isSqlite(db) ? "Yes" : "No");
db.get('select * from test where id=1 ', [1], function(err, row) {
if(row){
console.log("Row of data was: ", row);
}else if(err)
{
console.log("les guignols");
} // Prints [["Field1", "Field2",...]]
});
// This should ALWAYS be true, db object is open in the "Callback" if no errors occurred
console.log("Are we open yet (Inside Callback)? ", db.isOpen() ? "Yes" : "No"); // Yes
}
});
window.nsWebViewBridge.on("got",function(message){
console.log("Salut"+message);
console.log("hello");
});
console.log("bonjour");
}
我的 xml 文件 file :
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" actionBarHidden="true" xmlns:nota="@nota/nativescript-webview-ext">
<nota:WebViewExt src="~/html/index.html"> </nota:WebViewExt> </Page>
它内置了在 webview 中执行代码的函数。