从多个jquery移动页面传递参数
这是我已经奋斗了几个星期的事情,我希望有人能帮助我。我有两个表返回json数据,表1返回产品类别列表,表2返回产品列表。我已经设法将json数据返回从category表连接到我的query mobile app中的listview我现在的挑战是,当我单击一个类别时,我似乎无法让我的listview显示产品信息-我正在使用带有jquery mobile的多页应用程序,请提供帮助 sumary- 我需要知道如何传递所选产品类别的id以附加到我正在进行的REST调用中,以获取产品详细信息 如果你需要更多的清晰度,我会把它贴在这里 首先我们创建页面 product.html从多个jquery移动页面传递参数,jquery,json,rest,mobile,Jquery,Json,Rest,Mobile,这是我已经奋斗了几个星期的事情,我希望有人能帮助我。我有两个表返回json数据,表1返回产品类别列表,表2返回产品列表。我已经设法将json数据返回从category表连接到我的query mobile app中的listview我现在的挑战是,当我单击一个类别时,我似乎无法让我的listview显示产品信息-我正在使用带有jquery mobile的多页应用程序,请提供帮助 sumary- 我需要知道如何传递所选产品类别的id以附加到我正在进行的REST调用中,以获取产品详细信息 如果你需要更
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page" id="product_page">
<div data-role="header" class="">
<h3>Home</h3>
</div>
<div role="main" id="" class="ui-content">
<ul data-role="listview" id="product_list"></ul>
</div>
</div>
</body>
<script>
var product = {
"product": [
{
"product_name": "Product 1",
"product_category": "1"
},
{
"product_name": "Product 2",
"product_category": "2"
},
{
"product_name": "Product 3",
"product_category": "3"
}
]
}
$("#product_page").on("pageshow", function(event){
var list = "";
$.each(product, function(key, value){
$.each(value, function(key, value){
list += '<li><a href="category.html?product_category='+value.product_category+'" data-ajax="false">'+value.product_name+'</a></li>';
})
})
$("#product_list").html(list).trigger("create")
$("#product_list").listview( "refresh" )
})
</script>
<html>
家
var乘积={
“产品”:[
{
“产品名称”:“产品1”,
“产品类别”:“1”
},
{
“产品名称”:“产品2”,
“产品类别”:“2”
},
{
“产品名称”:“产品3”,
“产品类别”:“3”
}
]
}
$(“产品页面”)。在(“页面显示”,功能(事件){
var list=“”;
$。每个(产品、功能(键、值){
$.each(值、函数(键、值){
列表+='';
})
})
$(“#产品列表”).html(列表).trigger(“创建”)
$(“产品列表”).listview(“刷新”)
})
category.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"> </script>
</head>
<body>
<div data-role="page" id="category_page">
<div data-role="header" class=""></div>
<div role="main" id="" class="ui-content">
<p id="detail"></p>
</div>
</div>
</body>
<script>
$("#category_page").on("pageshow", function(event){
var product_category = getParameterByName("product_category");
$("#detail").html(product_category);
})
/** GET PARAMETER **/
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return results[1];
}
</script>
<html>
$(“类别页面”)。在(“页面显示”,功能(事件){
var product_category=getParameterByName(“product_category”);
$(“#详情”).html(产品类别);
})
/**获取参数**/
函数getParameterByName(名称)
{
名称=名称。替换(/[\[]/,“\\\[”)。替换(/[\]]/,“\\\]”);
var regexS=“[\\?&]”+name+“=([^&\\]*)”;
var regex=新的RegExp(regexS);
var results=regex.exec(window.location.href);
如果(结果==null)
返回“”;
其他的
返回结果[1];
}
请出示一些代码好吗?非常感谢。这无疑给了我我正在寻找的解决方案。另一方面。建议返回1个包含产品类别和pageinit调用中的产品的大json数据,然后按照上面显示的方式对其进行操作,还是我应该在每次单击categoryitem时进行json调用以过滤产品列表。谢谢你的帮助