我试图让我的表盘配置页面默认为用户之前在配置页面中保存的内容。目前,我有一个表盘,可以通过设置配置网页和 pebble-ja-app.js 从列表中选择 15 种颜色。用户提交他们想要的颜色,然后表盘会改变颜色,当用户返回配置网页时,网站会显示颜色列表,就像他们第一次访问网页时一样。我想让网页以他们之前选择的颜色开始。
任何帮助或建议将不胜感激。我所有的源代码都可以在https://github.com/palian/BlueFuturistic
我试图让我的表盘配置页面默认为用户之前在配置页面中保存的内容。目前,我有一个表盘,可以通过设置配置网页和 pebble-ja-app.js 从列表中选择 15 种颜色。用户提交他们想要的颜色,然后表盘会改变颜色,当用户返回配置网页时,网站会显示颜色列表,就像他们第一次访问网页时一样。我想让网页以他们之前选择的颜色开始。
任何帮助或建议将不胜感激。我所有的源代码都可以在https://github.com/palian/BlueFuturistic
你可以用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的示例)