0

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

当我从第 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" );
4

1 回答 1

3

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

el.trigger('create');
于 2012-11-23T15:14:43.277 回答