jquery mobile listview刷新异常(可能是计时)
很明显,这是一个时间问题。我有一个我正在开发的jQuery移动应用程序。我正在使用标准方法将项目附加到listview。然后在附加项目后调用jquery mobile listview刷新异常(可能是计时),listview,jquery-mobile,refresh,Listview,Jquery Mobile,Refresh,很明显,这是一个时间问题。我有一个我正在开发的jQuery移动应用程序。我正在使用标准方法将项目附加到listview。然后在附加项目后调用refresh。是的,我在html的头部有jQuery和jQuery mobile,是的,我使用的是'pageinit'事件,而不是$(document).ready()。以下是资料来源: JS GetApps: function () { $('#manage-apps-list').empty(); $.get('../../../con
refresh
。是的,我在html的头部有jQuery和jQuery mobile,是的,我使用的是'pageinit'
事件,而不是$(document).ready()
。以下是资料来源:
JS
GetApps: function () {
$('#manage-apps-list').empty();
$.get('../../../config.xml', function (data) {
$(data).find('app').each(function () {
var $this = {};
$this = $(this);
$('#manage-apps-list').append(
$('<li/>').append(
$('<a/>').attr('href', "#app-settings").attr('data-id', $this.find('id').text()).html($this.find('title').text()).off('click').on('click', function () {GetAppDetail($(this).attr('data-id'));})
)
);
});
});
$('#manage-apps-list').listview('refresh');
}
GetApps:function(){
$(“#管理应用程序列表”).empty();
$.get('../../../config.xml',函数(数据){
$(数据)。查找('app')。每个(函数(){
var$this={};
$this=$(this);
$(“#管理应用程序列表”)。附加(
$(“”)。追加(
$('
管理应用程序
这不是要查看的初始页面,而是一个子页面。结果如下:
我已经在我的应用程序中多次这样做了,而且它总是毫无问题地工作。我甚至使用了相同版本的$
和$。mobile
关于这一点,我已经看到了很多其他问题,但它们都没有调用
刷新
…你是对的。这是一个时间问题。你的刷新
方法没有等待列表完成其附加工作。因此,需要稍微重新构造你的获取
方法:
GetApps: function () {
$('#manage-apps-list').empty();
$.get('../../../config.xml', function (data) {
//set up an array for adding li to it.
var li = [];
//a temporary element to store "li"
var $li;
$(data).find('app').each(function () {
var $this = $(this);
//add the li HTML element to a vairable
$li = $('<li/>').append(
//you can also create the anchor tag like this - looks nicer :)
$('<a/>', {
"href": "#app-settings",
"data-id": $this.find('id').text(),
"html": $this.find('title').text()
}));
//add this $li to the main array of li
li.push($li);
});
//append li [] to ul
$('#manage-apps-list').append(li).promise().done(function () {
//wait for list to be added - thats why you wait for done() event in promise()
//add the click events to this - event delegation - this way your click event is added only once
$(this).on('click', 'a', function (e) {
//to prevent default click - just in case
e.preventDefault();
GetAppDetail($(this).attr('data-id'));
});
//then refresh
$(this).listview().listview("refresh");
});
});
}
GetApps:function(){
$(“#管理应用程序列表”).empty();
$.get('../../../config.xml',函数(数据){
//设置一个数组以向其中添加li。
var li=[];
//用于存储“li”的临时元素
var$li;
$(数据)。查找('app')。每个(函数(){
var$this=$(this);
//将li HTML元素添加到变量
$li=$(“”)。追加(
//您还可以像这样创建锚定标记-看起来更好:)
$(“在$之前刷新。get
结束。这看起来很棒。我看到了我现在犯的错误。我回家后一定会尝试这一点,并且一定会查看并重新构造我的其他应用程序,我可能也犯了错误。很高兴帮助:-)如果你认为这对你有帮助的话,就把它标记为正确的答案。如果你认为这对未来的访问者有帮助的话,就投票吧!-——它确实起作用了!在你的帖子里有一个很小的问题。我相信你在代码< >代码> < DONE()>代码>中意外地漏掉了代码>函数(<代码)>。再次感谢,我希望其他人也能从中学习。
GetApps: function () {
$('#manage-apps-list').empty();
$.get('../../../config.xml', function (data) {
//set up an array for adding li to it.
var li = [];
//a temporary element to store "li"
var $li;
$(data).find('app').each(function () {
var $this = $(this);
//add the li HTML element to a vairable
$li = $('<li/>').append(
//you can also create the anchor tag like this - looks nicer :)
$('<a/>', {
"href": "#app-settings",
"data-id": $this.find('id').text(),
"html": $this.find('title').text()
}));
//add this $li to the main array of li
li.push($li);
});
//append li [] to ul
$('#manage-apps-list').append(li).promise().done(function () {
//wait for list to be added - thats why you wait for done() event in promise()
//add the click events to this - event delegation - this way your click event is added only once
$(this).on('click', 'a', function (e) {
//to prevent default click - just in case
e.preventDefault();
GetAppDetail($(this).attr('data-id'));
});
//then refresh
$(this).listview().listview("refresh");
});
});
}