我先从jQuery手机和Phonegap开始。
我有一个类别选择器,并根据选择的类别显示属于该类别的复选框。下面是我可能展示的一个复选框组的例子。请注意,它是隐藏的,只有当用户在字段“类别”中选择“位置”时,我才会显示该字段。
<select name="select-choice-0" id="category" onchange="javascript:showboxes();updateresults();">
<option value="0">Select a category</option>
<option value="4">Catering</option>
<option value="1">Locations</option>
<option value="2">Music</option>
</select>
<div id="locationthemes_box" data-role="collapsible" style="display:none;">
<h3>Themes</h3>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>Theme</legend>
<input type="checkbox" name="locationthemes" id="checkbox-1" value="2" class="custom" />
<label for="checkbox-1">Castle</label>
<input type="checkbox" name="locationthemes" id="checkbox-2" value="3" class="custom" />
<label for="checkbox-2">Barn</label>
<input type="checkbox" name="locationthemes" id="checkbox-3" value="5" class="custom" />
<label for="checkbox-3">Restaurant</label>
<input type="checkbox" name="locationthemes" id="checkbox-4" value="8" class="custom" />
<label for="checkbox-4">Bar</label>
</fieldset>
</div>
</div>现在,我有更多要根据所选类别显示或隐藏的复选框组。我想防止我拥有页面中未显示的复选框的HTML。因为这将导致不必要的带宽使用。然后我想:也许我应该动态加载复选框组的内容,在用户更改类别选择框时立即对相关复选框和值进行web服务请求。
但这会导致大量的网页请求,我试图节省带宽。
所以我的想法是本地存储也许能解决我的问题。然后,我会将复选框值存储为名称/值字符串:
位置主题=2;城堡;3;谷仓;5;餐厅;8;酒吧
我的问题是:这是一种方法,还是有一种我不知道的最佳实践?
如果我的方式是建议的方式:任何使用本地存储和PhoneGap的例子都非常受欢迎!
发布于 2012-07-02 21:35:19
如果您使用Jquery Mobile的单页面概念,即拥有一个HTML并包含其中的所有页面,如下所示
<div data-role="page" id="page1">
<div data-role="page" id="page2">
<div data-role="page" id="page3">
<div data-role="page" id="page4">然后,您可以使用全局变量来存储值。
否则,您可以使用此处解释的localStorage http://docs.phonegap.com/en/1.8.1/cordova_storage_storage.md.html#localStorage
发布于 2013-02-09 18:01:34
我建议使用localStorage,因为如果需要,Android会毫不留情地杀死你的应用。一旦用户将你的应用程序放在后台一段时间,或者如果他让手机休眠或等待太长时间,那么应用程序可能会被终止。在这里,您可以确保始终将应用程序的状态或重要变量存储在localStorage中,然后在应用程序重启时再次获取这些数据(通过简单的启动检查)。
https://stackoverflow.com/questions/11291660
复制相似问题