Как запустить события из html (webview-ext) и перехватить их в nativescript? - PullRequest
0 голосов
/ 28 апреля 2020

Я использую webwiew-ext и хочу запускать события из формы webview-ext для получения данных и сохранять их с помощью сценария nativescript sqlite. Это пример, который я сделал для тестирования событий, но он не работает: мой js file:

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>

мой 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 файл:

<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>

1 Ответ

0 голосов
/ 29 апреля 2020

Я использую другой модуль веб-просмотра

, который имеет встроенные функции для выполнения кода в веб-просмотре.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...