How to sort the items before showing in Jquery ui autocomplete?
The jquery ui autocomplete does not sort the items for mine automatically. It uses the order of the items passed to the script, and filters from that.
This is the data source I should use( Chinese):
var availableTags = [
{value:"阿奇",desc:"看点数据的",groupId:2,userId:4},
{value:"阿甘",desc:"普通用户",groupId:4,userId:5},
{value:"阿爸劳动法地方",desc:"普通用户",groupId:2,userId:4},开发者_如何学JAVA
{value:"阿干",desc:"看点数据的",groupId:2,userId:4},
{value:"法地方的风景阿甘的",desc:"普通用户",groupId:2,userId:4}
];
or you can use English instead:
var availableTags = [
{value:"fruit",desc:"fruit",groupId:2,userId:4},
{value:"aGan",desc:"normal user",groupId:4,userId:5},
{value:"father's home ",desc:"normal user",groupId:2,userId:4}
];
So, how can I sort the order in Alphabetical??
Thank you very much!!
availableTags.sort(function(a, b) {
return a.value > b.value;
});
Try it here.
精彩评论