function pySegSort(arr, empty) { if (!String.prototype.localeCompare) return null; var letters = "*ABCDEFGHJKLMNOPQRSTWXYZ".split(''); var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split(''); var segs = [];// 存放数据 var py = [];// 存放首字母 var res = {}; var curr; $.each(letters, function (i) { curr = { letter: this, data: [] }; $.each(arr, function (k, v) { if ((!zh[i - 1] || zh[i - 1].localeCompare(v.userName) <= 0) && v.userName.localeCompare(zh[i]) == -1) { curr.data.push(this); } }); if (empty || curr.data.length) { py.push(this); segs.push(curr); curr.data.sort(function (a, b) { return a.userName.localeCompare(b.userName); }); } }); res["segs"] = segs; res["py"] = py; return res; }