我正在使用 jQuery Mobile 和 Phonegap 制作一个 Android 应用程序,但遇到了问题。用例如下:
- 屏幕 1. 选择浏览允许进行预订的企业列表或企业列表。
- 屏幕 2. 选择一种业务类型,例如医生或牙医
- 屏幕 3. 从下拉列表中选择一个位置以在
- 屏幕 4. 选择一项业务。
我的问题是,当用户进入可以选择业务的屏幕,然后决定返回并更改业务类型时,当他们再次看到选择位置屏幕时,所有位置都是重复的. 如果他们重复此过程,则下拉菜单中每个位置都有三个条目,依此类推。
(如果有帮助,请参阅http://imgur.com/a/8FMoZ上的屏幕截图)。
这些位置都是使用从数据库查询返回的 JSON 数据检索的。一旦它们被用于填充下拉列表,我已经尝试清空所有变量,以便下次遇到页面时它们中不会有数据。我还尝试使用 jQuery .empty 函数强制下拉列表为空,但由于某种原因,下拉列表中仍有重复条目。下拉菜单恢复正常的唯一时间是用户返回主页并再次执行该过程。这让我认为数据正在被缓存,否则主页上的某些内容会导致一切重新从头开始
任何想法为什么每次到达页面时下拉列表的所有条目都会重复。让我知道我是否可以提供一些东西来帮助理解问题。
编辑: 显示写入下拉选择菜单的代码:
$('#categorySearch').live('pageshow', function(event) {
theWindow = "categorysearch.html";
// //different ways of removing the options from within a select box, tried using them all since some didn't seem to function correctly but to no avail
// $('#search1').children().remove();
// $('#search1 option').remove();
// $('#search1').empty();
// $('#search1').html("");
// //different ways of removing the options from within a select box, tried using them all since some didn't seem to function correctly but to no avail
// $('#search2').children().remove();
// $('#search2 option').remove();
// $('#search2').empty();
// $('#search2').html("");
//variables for the necessary parameters to send to the query
var id = getUrlVarsCategorySearch()["id"];
var getCats = "";
var getParams = "";
//check which type of listing is being requested
if(submitBtn == "Book+Appointment")
{
getCats = "Bookable+Listings";
}
else
{
getCats = "All+Listings";
}
//the $_GET[] parameters to send
getParams = "?cat=" + id + "&submitBtn=" + getCats;
$('#search1').empty();
//add in empty option to tell user to select a county
$('#search1').append('<option value="" selected="selected">Select a county</option>\n');//add empty first option so the user will always have to change
//request state locations from the database
$.getJSON(serviceURL + 'getlocations.php' + getParams, function(data)
{
var stateLocations = data.items;
//fill the search box with these locations
$.each(stateLocations, function(index, stateLocation)
{
$('#search1').append('<option value="' + stateLocation.state + '">' + stateLocation.state + '</option>\n');
});
//trying to empty any variables once used so there shouldn't be data in them the next time the page is loaded
stateLocations = null;
data = null;
}).error(function(){ window.location = './error.html'; });
$("#search1").selectmenu("refresh", true);
$('#search1 option:first').attr('selected', 'selected');
});
编辑#2: 添加了示例 HTML 代码
<div id="categorySearch" data-role="page">
<form action="./linklist.html" method="get">
<div id="searchBox1">
<label for="search1">Located in:</label>
<select name="search1" id="search1">
</select>
</div>
</div>
<p align="center">
<input id="findBtn" type="submit" data-icon="search" value="Find" data-inline="true" disabled="disabled"/>
<input id="clearBtn" type="reset" data-icon="delete" value="Clear" data-inline="true"/>
</p>
</form>