JQuery Mobile .page() 函数导致无限循环?
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用
.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/