Pulpcore 和 Javascript 到 Java Applet 通信 [英] Pulpcore and Javascript to Java Applet communication

查看:25
本文介绍了Pulpcore 和 Javascript 到 Java Applet 通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Pulpcore Java 框架时遇到问题.我试图用小程序在页面上从 JavaScript 调用 Java 函数.小程序正确嵌入到页面上(pulpcore 生成了代码).JavaScript 代码是:

I have a problem using Pulpcore Java framework. I tried to call Java function from JavaScript on the page with applet. The applet is correctly embedded on the page (pulpcore generated the code). The JavaScript code is:

$(document).ready(function() {
    var self = $("#pulpcore_object")[0];
    self.show2();
});

我什至调试了这段代码,它正确地从 DOM 获取了小程序,但随后出现了这个 JavaScript 错误:

I even debugged this code and it gets applet from DOM correctly, but then there is this JavaScript error:

未捕获的异常:TypeError: 'self.show2' is not a function

Uncaught exception: TypeError: 'self.show2' is not a function

这让我有点困惑.使用

document.pulpcore_object.show2();

给出同样的错误.

我不知道我是否遗漏了什么或问题出在哪里.我什至找不到任何展示 JavaScript 与小程序通信的 Pulpcore 教程.

I don't know if I'm missing something or where the problem is. I can't even find any Pulpcore tutorial showing JavaScript to applet communication.

推荐答案

此答案由 f1ames 发布,作为问题内的答案:

This answer was posted by f1ames as an answer inside the question:

此代码有效:

$(document).ready(function() {
    var applet = $("#pulpcore_object")[0];
    var scene = applet.getCurrentScene();
    scene.method();
});

所以,我们得到了小程序,然后是主场景类,现在我们可以从场景类中调用任何公共方法.

So, we get the applet and then the main scene class and now we can call any public method from the scene class.

这篇关于Pulpcore 和 Javascript 到 Java Applet 通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆