JQuery Mobile .page() 函数导致无限循环? [英] JQuery Mobile .page() function causes infinite loop?

查看:28
本文介绍了JQuery Mobile .page() 函数导致无限循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

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);
        };

推荐答案

不要使用 .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/

这篇关于JQuery Mobile .page() 函数导致无限循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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