【发布时间】:2012-06-06 09:53:02
【问题描述】:
希望你们一切都好,并使用您的代码编辑器。
我的问题是如何将 url rel 传递给新页面以供将来使用?
让我举一个比 1000 字更好的例子。
在页面“A”上,我有指向页面“B”的 url,加载页面“B”html 我将该 url 直接指向页面“B”作为<a href="page-B.html" rel="{{id}}">{{deptName}}</a>(不要看{{}},它是 Mustache .js 标签)。
因此,当我单击该链接时,它会正常工作,将我指向页面“B”并加载我的新 html 布局(与页面“A”不同)。
现在因为我要从 JSON 中获取数据,所以我需要将 rel="{{id}}" 传递到 page-B 以告知我想要从 JSON 中获取哪些数据。
你有什么好的想法或实用的代码吗?
谢谢!
附言
在 $.delegate 的“B”页上,我需要该 id 来执行类似操作:
$.ajax({
beforeSend: function() { $.mobile.showPageLoadingMsg() }, //Show spinner
complete: function() { $.mobile.hidePageLoadingMsg() }, //Hide spinner
url: 'http://website.com/categoryJSON.ashx?&catId=THE_ID&callback=?',
dataType: 'json',
success: function(data) {
var template = $('#pageCategoryTpl').html();
var html = Mustache.to_html(template, data);
$('[data-role=content]:first').html(html);
}
});
【问题讨论】:
-
2 个问题 - 你累了什么?页面 B 是外部页面还是多页面模板的一部分?
标签: jquery json jquery-mobile