1

我开发了一个 simple.js 应用程序,它从 web 服务中获取公交车到达时间,问题是到目前为止它只适用于一站。

我想创建一个带有多选的配置页面,我可以在其中选择多个站点,将它们作为数组发送到卵石,并且在按下向上/向下按钮时,我想循环数组以显示不同的巴士站。我不擅长 C,我更喜欢 javascript 那是因为我使用了 simple.js。

我想知道和学习如何去做,因为我认为网上没有太多的文档和例子。

4

2 回答 2

1

所以配置页面是一个网页,您可以托管它并提供您的 URL,如上面 Ankan 所述。

像这样:

 Pebble.openURL('http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-js/configurable.html');

假设您决定在配置页面中获取用户的姓名和年龄,您将有两个文本字段供他们输入信息,然后您将有一个提交按钮。对于提交按钮,编写一个 javascript 函数,该函数使用 jQuery 获取文本字段 onclick 的值,然后将这些值保存到变量中,并使用 JSON 将它们发送到手机。这是一个完全创建的配置网页的示例:https ://github.com/pebble-hacks/js-configure-de mo

享受。

于 2014-09-18T18:01:20.473 回答
1

在 simple.js github 页面https://github.com/Meiguro/simplyjs/issues/11找到了类似的问题/问题。下面的代码示例来自 Meiguros 第一个答案。该代码将用户发送到您的配置网站,您应该将其配置为发回 json。

您可能可以复制用于启用配置窗口的代码示例并将其粘贴到主 pebble app.js 文件的开头。不要忘记添加 "capabilities": [ "configurable" ],您的 appinfo.json 文件。如果您使用的是 cloudpebble,您应该转到应用程序的设置页面并确保选中可配置框。

 var initialized = false;
    Pebble.addEventListener("ready", function() {
    console.log("ready called!");
    initialized = true;
    });
    Pebble.addEventListener("showConfiguration", function() {
    console.log("showing configuration");
        //change this url to yours
        Pebble.openURL('http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-js/configurable.html');
        });
        Pebble.addEventListener("webviewclosed", function(e) {
        console.log("configuration closed");
        // webview closed
        var options = JSON.parse(decodeURIComponent(e.response));
        console.log("Options = " + JSON.stringify(options));
        }); 

(https://github.com/pebble-hacks/js-configure-demo/blob/master/src/js/pebble-js-app.js - 在 https:// 之后删除空格)

然后将设置推回卵石,我认为您需要添加

Pebble.sendAppMessage(options);

就在之前

    console.log("configuration closed");
    // webview closed

我在这个 pebble 论坛线程http://forums.getpebble.com/discussion/12854/appmessage-inbox-handlers-not-getting-triggered-by-javascript-configuration-data的最后一篇文章中发现了这一点

您还可以在与 https://github.com/pebble-hacks/js-configure-demo 的代码示例相同的 git 中找到一个名为 configure.html 的配置网站示例,删除 https:// 后的空格

希望这对您实现目标有所帮助

于 2014-08-17T10:48:26.510 回答