JQuery Mobile触发器('create')命令不起作用

Ant*_*ony 21 mobile jquery controls triggers dynamic

今晚JQuery Mobile正在哭泣.我正在尝试构建自定义控件,所以我不会通过我的应用程序重复某些元素,这给了我很多时间.具体来说,我在HTML文件中有以下内容:

<div id="custom-header" data-role="header" data-position="inline" data-theme="f">
    <a href="index.html" data-icon="back" style="margin-top:5px" data-theme="b">Back</a>
    <div style="text-align: center; padding-top: 5px; padding-bottom: 3px"><img src="../images/logo.png" ></div>
    <a href="index.html" data-icon="home" style="margin-top:5px" data-theme="b">Home</a>
</div>
Run Code Online (Sandbox Code Playgroud)

在我的主文件中,我基本上是这样做的:

<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>        
<div data-role="page" id="test-console" data-theme="m">

    <div id="me-header"></div>

    <script>

        $.get('header.html', function (retData) {
            $('me-header').html(retData).trigger('create');
        });

     </script>

</div>
Run Code Online (Sandbox Code Playgroud)

所以这就是问题 - 标题与我将header.html的内容直接粘贴到我的JQM页面时的呈现方式不同.它几乎感觉像触发器('创建')没有做任何事情.

有任何想法吗?我已经烧了大约三个小时,像http://jquerymobiledictionary.pl/faq.html这样的教程似乎没有应用..

rbu*_*rbu 14

更改页眉,页脚或内容时,您可以pagecreate在页面上触发:

$('#me-header').closest(":jqmData(role='page')").trigger('pagecreate');
Run Code Online (Sandbox Code Playgroud)

这是一个jQM错误:https://github.com/jquery/jquery-mobile/issues/2703.根据问题报告中的评论,pagecreate多次调用可能会导致问题,如https://github.com/jquery/jquery-mobile/issues/2703#issuecomment-4677293中所述.


Ant*_*ony 8

我相信我找到了"最好"的答案.简而言之,"标题"和"页脚"类型的数据角色元素不是标准小部件.它们是某种混合构造.我通过浏览JQueryMobile的源代码找到了这个.它们没有'create'方法,因此无法调用.

我的解决方法是直接将类应用于我的代码,而不是期望小部件为我做.不理想,但它运作良好.

  • 这很有趣.标题是让我疯狂的标题. (2认同)