gpt4 book ai didi

javascript - jquery mobile multipage与javascript模板,并不总是 "refresh"

转载 作者:行者123 更新时间:2023-11-28 20:45:31 25 4
gpt4 key购买 nike

我有一个多页 jQuery 移动页面。

当我从第 1 页转到第 2 页时,我看到我使用 Handlebars 动态创建的模板。

模板:

<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 移动外观/主题)。

编辑

对于我的示例,我必须执行以下操作:

$('#share').html(html).trigger( "create" );

最佳答案

您需要在 html 元素上触发 create 事件,例如

el.trigger('create');

关于javascript - jquery mobile multipage与javascript模板,并不总是 "refresh",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13531701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com