Titanium.Contacts.showContacts,按字母顺序排名

时间:2012-04-19 12:04:52

标签: iphone titanium-mobile

我正在使用Titanium开发移动应用。我遇到了一个问题,我想要显示联系人列表。我使用以下代码来显示联系人列表

Titanium.Contacts.showContacts({ });

我收到了联系人列表,但它显示了姓氏的排序顺序。我希望列表以名字的排序顺序显示。

任何帮助将不胜感激

1 个答案:

答案 0 :(得分: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);
}