2012-04-19 90 views
1

我正在使用Titanium開發移動應用程序。我遇到了問題,我想顯示聯繫人列表。我用下面的代碼來顯示聯繫人列表Titanium.Contacts.showContacts,按字母順序名

Titanium.Contacts.showContacts({ }); 

我收到聯繫人列表,但它顯示姓氏的排序順序。我希望列表以名字的排序順序顯示。

任何幫助將不勝感激

回答

2

有一個屬性Ti.Contacts.CONTACTS_SORT_FIRST_NAME希望這會有所幫助。還有CONTACTS_KIND_ORGANIZATION和CONTACTS_KIND_PERSON。

var g = Ti.Contacts.getAllGroups();//Getting all the groups on the contacts table 

var m = g[0].members();//select a group and check if it has members 
Ti.API.info(m)// my group was empty so i have to add people 

var p = Ti.Contacts.getAllPeople()// get all the contacts 
for (var i in p){//group and add people to your group 
    g[0].add(p[i]); 
    Ti.API.info(p[i].firstName); 
    Titanium.Contacts.save()// you have to save new changes in IOS 
} 
g[0].sortedMembers(Ti.Contacts.CONTACTS_SORT_FIRST_NAME);// FINALLY WE CAN SORT 

m = g[0].members();// get the members 

for (var i in m){// verify they are in order 
    Ti.API.info(m[i].firstName); 
}