BlackBerry webworks 使用 JavaScript 实现奇怪的行为

发布于 2024-11-01 13:29:03 字数 1812 浏览 5 评论 0原文

我是 BlackBerry 开发新手,多年来一直开发 iPhone 应用程序。

我正在尝试做一个如下所示的简单菜单,调用 onLoad:

function initMenus() {
  var item = new blackberry.ui.menu.MenuItem(false, 1, "Save", saveMe);
  var item2 = new blackberry.ui.menu.MenuItem(false, 2, "Load", loadMe);
  blackberry.ui.menu.addMenuItem(item);
  blackberry.ui.menu.addMenuItem(item2);
}

function saveMe()
{
  localStorage.pixels = window.pageYOffset;
}

function loadMe()
{
  window.scrollTo(0, localStorage.pixels);
}

在配置文件中,我有:

<?xml version="1.0" encoding="utf-8"?>
<widget xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0" rim:header="RIM-Widget:rim/widget" xmlns="http://www.w3.org/ns/widgets">
  <name>007</name>
  <description>Sample Application created using the BlackBerry Widget SDK that demonstrates how to use the Menu and MenuItem objects found within the Widget API collection.</description>
  <author href="http://na.blackberry.com/eng/developers/browserdev/widgetsdk.jsp" rim:copyright="2010" email="[email protected]">Adam Stanley</author>
  <content src="index.html" />
  <feature id="blackberry.ui.menu" required="true" version="1.0.0.0" />
  <rim:loadingScreen backgroundColor="#c0c0c0" />
  <license href="" />
</widget>

安装了 WebWorks 最后的 SDK 后,我可以尝试使用 OS5 和 OS6 系列的模拟器。

现在,有了 OS6 模拟器,一切都很好。 JavaScript 函数被正确调用。

OS5 模拟器会显示菜单项,但一旦我单击它们,就什么也没有发生。我还尝试使用简单的警报,而不是在 localStorage 中保存和加载数据,但单击菜单项后根本不会调用函数。

我做错了什么?

我知道在同一应用程序中声明 blackberry.ui.dialogblackberry.ui.menu 时存在一个已知问题,但我只是声明 blackberry.ui.menu

I am new to BlackBerry development, having developed iPhone apps for years.

I am trying to do a simple menu like the following, invoked onLoad:

function initMenus() {
  var item = new blackberry.ui.menu.MenuItem(false, 1, "Save", saveMe);
  var item2 = new blackberry.ui.menu.MenuItem(false, 2, "Load", loadMe);
  blackberry.ui.menu.addMenuItem(item);
  blackberry.ui.menu.addMenuItem(item2);
}

function saveMe()
{
  localStorage.pixels = window.pageYOffset;
}

function loadMe()
{
  window.scrollTo(0, localStorage.pixels);
}

In the configuration file, I have:

<?xml version="1.0" encoding="utf-8"?>
<widget xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0" rim:header="RIM-Widget:rim/widget" xmlns="http://www.w3.org/ns/widgets">
  <name>007</name>
  <description>Sample Application created using the BlackBerry Widget SDK that demonstrates how to use the Menu and MenuItem objects found within the Widget API collection.</description>
  <author href="http://na.blackberry.com/eng/developers/browserdev/widgetsdk.jsp" rim:copyright="2010" email="[email protected]">Adam Stanley</author>
  <content src="index.html" />
  <feature id="blackberry.ui.menu" required="true" version="1.0.0.0" />
  <rim:loadingScreen backgroundColor="#c0c0c0" />
  <license href="" />
</widget>

Having installed the WebWorks last SDK, I can try with emulators of OS5 and OS6 families.

Now, with OS6 simulators everything is fine. JavaScript functions are properly called.

With OS5 simulators menu items are shown, but once I click on them, just nothing happens. I tried also with simple alerts, rather than to save and load data in localStorage, but functions are simply not called after clicking menu items.

What am I doing wrong?

I am aware that there is a known issue when declaring blackberry.ui.dialog and blackberry.ui.menu in the same application, but I'm just declaring blackberry.ui.menu.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌面超妹 2024-11-08 13:29:03

我注意到在两个调用的函数中,您都试图访问 localStorage。在 OS5 上,不支持常规 HTML5 localStorage,仅支持 Google Gears 方法。您在项目中使用 html5_init.js 吗? 按照这些说明添加它。它是适用于 OS5 的 Google Gears 到 HTML5“转换器”。

这可能不是您的问题,但如果您正在编写可在两个版本的操作系统上运行的 Webworks 应用程序,那么无论如何您都需要它。

I noticed in both of the functions called, you're trying to access localStorage. On OS5, the regular HTML5 localStorage isn't supported, only Google Gears methods. Are you using the html5_init.js in your project? Follow these instructions to add it. It is a Google Gears to HTML5 "converter" for OS5.

That may not be your problem, but you'll need it anyway if you're writing a Webworks app that will work on both version of the OS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文