我正在制作一个有两个页面的jQuery Mobile / Phonegap应用程序。第一页有一个搜索输入,用户可以在其中添加书名或作者,然后第二页是根据与给定值匹配的数量显示结果的位置。
到目前为止,我已经设法从搜索输入中获取值,并成功接收到第二页中的值。
我的 jQuery 代码在外部文件上,并被添加到 jQuery.js 和 jQuerMobile.js 之间的 index.html 文件中
//this is from the first page
// capture the user input, and change page to search_results.html
function handlePageChange() {
if ($('#search-1').val().length > 0) {
$.mobile.changePage('search_results.html', {
dataUrl : "search_results.html",
data : {
'input' : $('#search-1').val()
},
reloadPage : false,
changeHash : true
});
} else {
alert('Search input is empty!');
}
}
//Handle the page-change action after user has pressed the button = changePage
$(document).on('pagebeforeshow', "#index", function() {
$(document).on('click', "#changePage", handlePageChange);
});
//this is from second page
// get data from search input form index.html
function getSearchValue() {
var parameters = $(this).data("url").split("?")[1];
parameter = parameters.replace("input=", "");
alert(parameter);
}
//Trigger after page is loaded
$(document).on('pageshow', "#search_results", getSearchValue);
但我被困在两件事上。首先看一下 jQueryMobile,它让我感到困惑,好像使用哪个事件来使用我的 ajax 调用 API。
我是否应该只是现有事件侦听器的另一个回调函数pageshow
。
然后我想listview
用 Google Books API 的结果填充我的结果,但我找不到任何好的例子。
至少,我想listview
用缩略图和标题显示书籍,当有人点击其中一本书时,它将转换到另一个页面,在其中显示有关该书的更多详细信息。
我怎么能根据id来做到这一点。
即使没有代码的概念也受到欢迎。谢谢