Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

javascript - JQuery Mobile .page() function causes infinite loop?

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);
        };
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...