且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在主干视图的动态客户端模板中呈现 jQuery Mobile?

更新时间:2022-10-24 22:57:21

如评论中某处所述 这个问题,你可以在渲染你的页面后这样做:

$("#pageId").trigger("create");

这将强制 jQuery Mobile 更新您的页面并解决您的问题.

I'm building a mobile website using Brunch.

For the user interface, I want to use jQuery Mobile.

I started out adapting the existing home_view (Backbone.View) as such:

class exports.HomeView extends Backbone.View
  id: 'home-view'

  render: ->
    console.log "render() homepage"

    $(@el).html require('./templates/home')

    $.mobile.changePage('#homepage', 'slide', false, false)
    console.log $(@el)

    @

This doesn't work, and I suspect it's because Backbone 'injects' the html before or after jQuery Mobile is initialized or something?

I can inspect the markup using Firebug and Chrome's Inspect Element, but the div elements are set to display:none; (so again this seems to point to jQuery Mobile not initializing or something like that)

./templates/home is a simple 'eco' template with some basic jQuery Mobile markup, and it looks like this: (and gets injected into the body tag)

<div data-role="page" id="homepage">
    <div data-role="navbar">
        <ul>
            <li><a href="/" class="ui-btn-active">Home</a></li>
        <li><a href="#helppage">Help</a></li>
    </ul>
    </div><!-- /navbar -->

    <div data-role="content">
        <div id="home">
            <h1>Home</h1>
        </div>
    </div>
</div>

I've searched around SA and Google for solutions but didn't manage to pull it off. Any tips would be highly appreciated. Thanks!

As stated somewhere in a comment on this question, you can do this after rendering your page:

$("#pageId").trigger("create");

This will force jQuery Mobile to update your page and fix your problem.

相关阅读

技术问答最新文章