ajax请求后,重新初始化Jquery Mobile的所有元素? [英] Re-initialize all elements of Jquery Mobile after ajax Request?

查看:100
本文介绍了ajax请求后,重新初始化Jquery Mobile的所有元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下页面,

I have the following page,

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="<%= ResolveUrl("~/css/jquery.mobile-1.3.0.min.css") %>" />
</head>
<body>
    <form id="form1" runat="server">
    <div>  
         <div data-role="page" id="newsDeatils">
            <div data-role="content">
                <h3 id="newsTitle"></h3>
                <p id="newsCategory"></p>
                <div id="newsDescription"></div>   
            </div>
        </div>
    </div>
    </form>
    <script src="<%= ResolveUrl("~/js/jquery.min.js") %>"></script>
    <script>
        $(document).bind("mobileinit", function () {
            $.mobile.autoInitializePage = false;
        });
    </script>
    <script src="<%= ResolveUrl("~/js/jquery.mobile-1.3.0.min.js") %>"></script>    
    <script src="<%= ResolveUrl("~/js/knockout-2.2.0.js") %>"></script>
    <script src="<%= ResolveUrl("~/js/NewsDetails.js" )%>"></script>
    <script>
       $.mobile.initializePage();
    </script>
</body>
</html>

NewsDetails.js将发送一个ajax请求,然后填入 newsDescription div 与表。但没有任何工作?

NewsDetails.js will send an ajax request then fill the newsDescription div with a table. But nothing is working?

推荐答案

不是延迟初始化整个页面,而是最好让它全部被初始化,然后初始化新的代码。在jQm v1.3.2及更早版本中,您可以通过将以下代码添加到成功回调中来完成此操作。

Rather than delay initialising the whole page it would be better to allow it all to be initialised, then initialise just the new code. In jQm v1.3.2 and earlier you could do this by adding the following code to your success callback.

$('#newsDescription table').trigger('create');

这将允许整个页面进行初始化并防止向用户呈现未打印页面有一个缓慢的网络连接,可能会导致您的ajax请求需要一段时间。

This will allow the whole page to initialise and prevent a flash of an unstyled page to the user if they have a slow network connection which could cause your ajax request to take a while.

这篇关于ajax请求后,重新初始化Jquery Mobile的所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆