2013-06-19 67 views
0

我试图在jquerymobile listview中显示所有联系人。很抱歉,我只收到一个联系人列出/显示。 我使用的代码below.Thanks在Jquerymobile中显示联系人Listview(phonegap)

function onDeviceReady() { 
    // find all contacts with 'Bob' in any name field 
    var options = new ContactFindOptions(); 
    options.filter=""; 
    options.multiple=true; 
    var fields = ["displayName", "phoneNumbers", "photos"]; 
    navigator.contacts.find(fields, onSuccess, onError, options); 
    } 

    // onSuccess: Get a snapshot of the current contacts 
    // 
    function onSuccess(contacts) { 
    for (var i=0; i<contacts.length; i++) { 
    if(null != contacts[i].phoneNumbers) 
     { 
      for(var j=0;j<contacts[i].phoneNumbers.length;j++) 
      { 
      $('.real').append("<li'><a><img src='foto/user.png'/><h4 >" + contacts[i].displayName +"</h4><p>"+ contacts[i].phoneNumbers[j].value +"</p></a> </li>").listview('refresh'); 

      } 
     } 
    } 
} 
// onError: Failed to get the contacts 
// 
function onError(contactError) { 
    alert('onError!'); 
} 
+0

Searchng for the same issue ..你有没有找到解决方案呢?谢谢! – EranLevi

+0

YES,删除“.listview('refresh');”。 –

回答

0

虽然你已经回答了你自己的问题,只是为了突出对我加入我的回答这个问题。

Docs

如果将项目添加到一个列表视图,你需要调用它的刷新()方法以更新的款式和创建要添加任何嵌套列表。例如:

请注意,refresh()方法仅影响附加到列表的新节点。这是出于性能原因而完成的。刷新过程会忽略任何已经增强的列表项目。这意味着如果您更改已经增强的列表项目上的内容或属性,这些内容或属性将不会被反映出来。如果您希望更新列表项目,请在调用刷新之前将其替换为新的标记。

对于你的问题,你应该做下面的事情。

$('.real').listview('refresh'); 
相关问题