我正在使用来自 AJAX 响应的数据动态创建 ListView 。它成功地创建了 listview 并填充它,但是当我在其上调用 JQM 的 .page() 函数时,它似乎进入了一个无限循环,其中 listview 被永远追加。
这是 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);
};
最佳答案
而不是使用 .page()
使用 .trigger( "create");
jQuery Mobile 团队更新:7 月 18 日那一周 http://jquerymobile.com/blog/
关于javascript - JQuery Mobile .page() 函数导致无限循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6624664/