2012-04-19 71 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); 
}