【问题标题】:setting the configuration page to specific defaults already saved in the Pebble 3.0 SDK将配置页面设置为已保存在 Pebble 3.0 SDK 中的特定默认值
【发布时间】:2015-09-03 16:24:25
【问题描述】:

我试图让我的表盘配置页面默认为用户之前在配置页面中保存的内容。 目前,我有一个表盘,可以通过设置配置网页和 pebble-ja-app.js 从列表中选择 15 种颜色。用户提交他们想要的颜色,然后表盘改变颜色,当用户返回到配置网页时,网站有颜色列表,就像他们第一次访问网页一样。我想让网页以他们之前选择的颜色开始。

任何帮助或建议将不胜感激。 我所有的源代码都可以在https://github.com/palian/BlueFuturistic获得。

【问题讨论】:

    标签: javascript pebble-watch pebble-sdk cloudpebble pebble-js


    【解决方案1】:

    您可以为此使用localstorage

    function getConfigData() {
        var backgroundColorPicker = document.getElementById('background_color_picker');
        var highContrastCheckbox = document.getElementById('high_contrast_checkbox');
    
        var options = {
          'background_color': backgroundColorPicker.value,
          'high_contrast': highContrastCheckbox.checked
        };
        // Save for next launch
        localStorage['background_color'] = options['background_color'];
        localStorage['high_contrast'] = options['high_contrast'];
        console.log('Got options: ' + JSON.stringify(options));
        return options;
      }
    

    加载配置页面后使用自调用 JavaScript 函数设置 GUI 状态:

    (function() {
        var backgroundColorPicker = document.getElementById('background_color_picker');
        var highContrastCheckbox = document.getElementById('high_contrast_checkbox');
        // Load any previously saved configuration, if available
        if(localStorage['high_contrast']) {
          highContrastCheckbox.checked = JSON.parse(localStorage['high_contrast']);
          backgroundColorPicker.value = localStorage['background_color'];
        }
      })();
    

    (来自https://github.com/pebble-examples/slate-config-example的示例)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多