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

发布于 2024-11-19 11:42:16 字数 872 浏览 5 评论 0原文

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

这是 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 是一个函数,允许我在 JQM 加载页面级脚本时运行它们。它在基本模板或index.html中定义:

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

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.

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

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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿看小鸭子会跑 2024-11-26 11:42:16

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文