如何从html(webview-ext)启动事件并将其捕获为本机脚本?

问题描述 投票:0回答:1

我正在使用webwiew-ext,我想从webview-ext形式启动事件以获取数据并使用nativescript脚本sqlite保存这是我测试事件的示例,但是不起作用:我的js文件:

function callFromNativeScript() {
    window.nsWebViewBridgee.emit("got", { huba: "hop" });
    console.log("got a message from nativescript");
}

像在标题中一样加载到html文件中:

<script  src="../js/index.js"  type="text/javascript"></script>

我的本机脚本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文件文件:

<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>
javascript html webview nativescript
1个回答
0
投票

我正在使用another webview module

© www.soinside.com 2019 - 2024. All rights reserved.