javascript JQuery Mobile .page() 函数导致无限循环?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6624664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:19:16  来源:igfitidea点击:

JQuery Mobile .page() function causes infinite loop?

javascriptjqueryjquery-mobiledhtml

提问by sw00

I'm dynamically creating a listview with data from a AJAX response. It successfully creates the listview and populates it, but when i call JQM's .page() function on it, it seemingly goes into an infinite loop where the listview is appended forever.

我正在使用来自 AJAX 响应的数据动态创建列表视图。它成功地创建了列表视图并填充了它,但是当我在它上面调用 JQM 的 .page() 函数时,它似乎进入了一个无限循环,列表视图永远附加在其中。

Is this a bug in JQM or am I doing something wrong?

这是 JQM 中的错误还是我做错了什么?

pageScript(function($context){
    $context.bind("pagecreate", function(event, ui){
        createMenu(); //function that deletes existing ul#menu and dynamically creates new one. 
        $('ul#menu').page(); //here's where it causes a problem
        $('#menu a').bind('click', function(){
            $.mobile.changePage($(this).attr("href"), {pageContainer: $("#primary-content"), transition: "fade", changeHash: false, reloadPage: true});
            return false;
        });
    });
});

pageScript is a function that allows me to run page-level scripts when they are loaded by JQM. It's defined in the base template or index.html:

pageScript 是一个函数,它允许我在 JQM 加载页面级脚本时运行它们。它在基本模板或 index.html 中定义:

function pageScript(func) {
            var $context = $("div:jqmData(role='page'):last");
            func($context);
        };

回答by Joe

Instead of using .page()use .trigger( "create" );jQuery Mobile team update: Week of July 18th http://jquerymobile.com/blog/

而不是使用.page()使用.trigger( "create" );jQuery Mobile 团队更新:7 月 18 日的一周http://jquerymobile.com/blog/