我有一個多頁面的jQuery手機頁面。jquery手機多頁面javascript模板,並不總是「刷新」
當我從第1頁轉到第2頁時,我看到我的模板是使用把手動態創建的。
模板:
<script id="history-template" type="text/x-handlebars-template">
<div data-role="collapsible" id="share_history" >
<h3>{{share_title}}</h3>
{{#each historyItem}}
<h2>Shared with {{shared_with}}</h2>
{{#list people}}{{firstName}} {{lastName}}, {{role}}{{/list}}
{{/each}}
</div>
</script>
的JavaScript:
var context = {
share_title: "View Share History",
historyItem: [
{
shared_with: "with a group",
people: [
{firstName: "Bob", lastName: "Wong", role: "Dad" },
{firstName: "Tina", lastName: "Turner", role: "Guardian" },
{firstName: "Modest", lastName: "Mouse", role: "Dad" }
]
},
{
shared_with: "with 3 people",
people: [
{firstName: "Baily", lastName: "Wong", role: "Dad" },
{firstName: "Gina", lastName: "Turner", role: "Guardian" },
{firstName: "Modest", lastName: "Mouse", role: "Dad" }
]
}
]
};
var source = $("#history-template").html();
var template = Handlebars.compile(source);
Handlebars.registerHelper('list', function(people, options) {
var out = "<ul class=>";
for(var i=0, l=people.length; i<l; i++) {
out = out + "<li>" + options.fn(people[i]) + "</li>";
}
return out + "</ul>";
});
var html = template(context);
$('#share').html(html);
$.mobile.changePage('#add-edit');
當我從第1頁第2頁(在我的多頁佈局)去它的工作原理(好)。
但,如果我點擊後退按鈕,然後回到第2頁,我看到我的內容...減去額外的標記jQuery Mobile的增加(即我看到的內容,但不是我的jQuery Mobile的外觀/主題)。
編輯
對於我的例子中,我必須做到以下幾點:
$('#share').html(html).trigger("create");
你需要[觸發](http://jquerymobile.com/demos/1.2.0/docs/pages/page-scripting.html)在您的頁面上創建一個「創建」來告訴JQM初始化您的小部件。 – Jack