English 中文(简体)
动态添加列表项到 Jquery Mobile 中的未排序列表
原标题:Dynamically add list item to un-ordered list in Jquery Mobile

在有人指使我提出这里关于堆积流的模拟问题之前,我搜索并阅读了所有已经提供的无用的解决办法,并尝试了所有解决办法。

<ul data-role= listview  data-theme= b  data-inset= true  id= resultsList >
   <!-- keep empty for dynamically added items -->
</ul>

然后,在你的喷射标本/口供中,你会这样(记住,我从JSON的物体上得到我的数据):

var resultLength = jsonObject.results.length;
var listItems = [];

for(var i=0;i<resultLength;i++){
   var firstname = jsonObject.results[i].FN;
   var lastname = jsonObject.results[i].SN;

   //Add result to array
   listItems.push("<li><a href= # >"+firstname+" "+lastname+"</a></li>");
}

//Append array to list and refresh
$( #resultsList ).append(listItems.join(   ));
$( #resultsList ).listview( refresh );

但是,这不管用。我最近才刚到,所以我可能在某个地方犯一个很愚蠢的错误。如果有人知道为什么这样行不通的话,我很感激!我很感激!我花了2天时间才完成这个任务。如果需要更多信息,请不要犹豫询问。

编辑 - 按要求添加 JSON

{"results":
[
 {   "GUID":"F45B0504-376C-4772-81C2-B920E23E1332",
     "I#":"4202265241081",
     "FN":"JOHN",
     "DOB":"1942-02-26",
     "SEX":"M",
     "SN":"KHUNOU",
     "U#":"VH00041750",
     "TYPE":"P"},

{    "GUID":"BB69F24F-424A-4B10-8A48-E94197894855",
     "I#":"3909035071082",
     "FN":"JOHN E",
     "DOB":"1939-09-03",
     "SEX":"M",
     "SN":"RIVETT CARNAC",
     "U#":"VH00156354",
     "TYPE":"P"
}
],
"ok":"true"}
问题回答

您的代码看起来不错, 并且将 JSON 带出方程式显示它有效 : < a href="http://jsfiddle.net/b5h5Y/" rel="no follow" >http://jsfiddle. net/b5h5Y/

既然代码起作用了,也许就贴上JSON本身的样本, 或者你访问它的方式, 似乎就是弱点?





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签