Google 小工具布尔偏好似乎不起作用
我只是想在 Google Gadget 中读取用户的布尔首选项,但似乎该首选项根本不会被保存,而且我只能得到 default_value 是什么。我已将其分解为一个非常简单的测试用例。这是我的测试小工具规范:
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Gadget to test bool">
</ModulePrefs>
<UserPref name="testpref" display_name="Test Boolean Preference" default_value="true" datatype="bool" />
<Content type="html">
<![CDATA[
<script type="text/javascript">
var prefs = new gadgets.Prefs();
alert(prefs.getBool('testpref'));
</script>
]]>
</Content>
</Module>
我期望看到的是针对用户在首选项对话框中选择的任何内容显示带有 true
或 false
的警报。但是,用户的首选项完全被忽略,没有保存,甚至我的默认值也没有显示在首选项中。当我为默认值指定 true 时,首选项复选框保持未选中状态。
我缺少什么?
编辑:我正在尝试在 Google Apps Google 协作平台起始页上实现此功能。
I am simply trying to read a user's boolean preference in a Google Gadget, but it seems that the preference is never getting saved at all, and I only ever get whatever the default_value is. I've broken this down into a very simple test case. Here is my test gadget spec:
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Gadget to test bool">
</ModulePrefs>
<UserPref name="testpref" display_name="Test Boolean Preference" default_value="true" datatype="bool" />
<Content type="html">
<![CDATA[
<script type="text/javascript">
var prefs = new gadgets.Prefs();
alert(prefs.getBool('testpref'));
</script>
]]>
</Content>
</Module>
What I expect to see is an alert with true
or false
in it for whatever the user has chosen in the preferences dialog. However, the user's preferences are completely ignored, not saved, and even my default value isn't shown in the preferences. When I specify true for the default value, the preference checkbox remains unchecked.
What am I missing?
Edit: I am trying to get this working on a Google Apps Google Sites Start Page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 iGoogle 中测试了您的示例代码,它似乎工作正常。这是一个可以选中或取消选中的框,并且会使用正确的值触发警报。
据我所知,某些类型的小工具容器不允许用户首选项 - 因此,在 iGoogle 中工作的小工具将无法在标准 Google 协作平台页面(用户可自定义类型页面除外)中正常工作。
iGoogle 中代码“不工作”的另一个常见问题是小工具代码的缓存。要强制小工具不缓存,请将“?nocache”添加到小工具 URL...
I tested your sample code in iGoogle and it seems to be working correctly. That is a box can be checked or unchecked and the alert is fired with the correct value.
As far as I know certain types of gadget containers do not allow user preferences - so the gadget that will work in iGoogle will not work correctly in standard Google Sites pages (apart from user customisable-type page).
Another common problem with code "not working" in iGoogle is caching of the gadget code. To force a gadget not to cache add "?nocache" to the gadget URL...