2013-03-21 18 views
0

我有这样的功能:如何传递参数到动态页面在jQuery Mobile的(函数内)

var getData = function() { 

    for(var i = 0, j = localStorage.length; i < j; i ++) { 
     var newKey = localStorage.key(i); 
     var newValue = localStorage.getItem(newKey);  
     var newObj = JSON.parse(newValue); 
     var ulListView = $('#container').append('<ul data-role="listview" data-split-icon="minus" data-split-theme="c" data-inset="true" id="ulOrigin'+i+'"></ul>'); 
     var objPage = $(newObj[1].value).trigger('create'); //Create an obj. of type page 
     var strnDynPage = JSON.stringify(objPage.selector); //Extract the selector and convert it into a string to use for the id  

     var insideLi = $('#ulOrigin'+i).append('<li><a href="#'+objPage.selector+'"><img src="images/'+newObj[0].value+'.png"><h2>'+newObj[1].value+'</h2><p>'+newObj[0].value+'</p></a><a href = "#deleteObject" data-rel = "popup" data-position-to = "window" data-transition = "pop">Delete Entry</a></li>');  
     //var dynPage = $('<div data-role = "page" id = "'+newObj[1].value+'"><div data-role = "header"></div><div data-role = "content"></div><div data-role = "footer"></div>"</div>'); 
     console.log(typeof objPage.selector); 

    } 


}; 

在此函数中,我创建了一些可点击的项目动态列表。我希望能够为每个列表分配一个动态页面。

事情我已经尝试:

在函数创建一个动态页面,得到.selector(它返回一个字符串值),并将其分配给A HREF。的名单。我没有收到任何错误,但网页无法打开。有关这件事的任何想法?非常感谢。

+1

让我们看到一些代码或的jsfiddle – ITroubs 2013-03-21 15:56:52

+0

不要只说你试过..显示它。 – 2013-03-21 15:58:40

+0

我不喜欢我和++之间的空间。但为什么不使用jQuery? '$ .each(localStorage,function(key,item){...}' – mplungjan 2013-03-21 16:00:29

回答

0

既然是jQuery Mobile的则

<a href="#'+objPage.selector+'"> 

我们需要看到什么

objPage.selector 

正在恢复,加上您的HTML生成的问题

+0

这就是jQuery Mobile works。 – Gajotres 2013-03-21 16:14:20

+0

Op说这是使用jquery,无论哪种方式都必须有wr ong与输出 – Huangism 2013-03-21 16:15:24

+0

Theres可能有错误的输出,但你的答案是不正确的。 – Gajotres 2013-03-21 16:16:50