how to use jquery-mobile listview to link to inner pages with UrlVars?

血红的双手。 提交于 2019-12-13 04:24:00

问题


I have a problem with jquery-mobile listview.

I some inner pages (#page1, #page2,..) into the same html file. e.g. in #page2, I have a jquery listview object:

<ul id="itemList" data-role="listview"></ul>  

Each item of the listview has a URL that is the inner page plus an index generated in a js file into a HEAD of html file. Some of code into the js file:

$.each(data, function(index, record) {
$('#itemList').append('<li><a href="#page2?id=' +  record.id + '"></a></li>');
});
$('#itemList').listview('refresh');

The mouse over items shows differents links with each index "id". But only the first click works and goes to the correct page e.g. page2?id=id1 Returning to the page with the listview and clicking over another item e.g. /page2?id=id2, the page displayed is the previous (the first link clicked) page with id1

It could be a problem of the UrlVars notation? When I used href="page.html?id=.... or href="#page without additional indexes there is no problem and listview works fine. But with href="#page?id=... dosen't work. Sound like a refresh problem? Maybe related with the DOM?

Any idea?

I'm Sorry, I do not know if I have explained the problem correctly.

Thank you! Best Regards.


回答1:


Try the following:

$.each(data, function(index, record) {
    $('#itemList').append('<li><a href="#page2?id=' +  record.id + '">' + record.id + '</a></li>');
});

You don't have to repeat code since you are already looping over that same piece inside the each function.



来源:https://stackoverflow.com/questions/16676948/how-to-use-jquery-mobile-listview-to-link-to-inner-pages-with-urlvars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!