Skip to content

Commit 8575a08

Browse files
committed
优化搜索结果排序顺序 jaywcjlove#86
1 parent 491a8d4 commit 8575a08

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎template/js/index.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@
102102
}
103103
}
104104
resultData.sort(function (a, b) {
105-
// if (a.nIdx === -1 || b.nIdx === -1) {
106-
// return 1;
107-
// }
108105
return a.nIdx - b.nIdx
109106
}).sort(function(a, b) {
110107
return a.n.length - b.n.length;
108+
}).sort(function (a, b) {
109+
if (b.n.indexOf(self.query) < 0) {
110+
return -1;
111+
}
112+
return a.n.indexOf(self.query) - b.n.indexOf(self.query);
111113
});
112-
console.log('resultData:', resultData)
113114
resultData = resultData.slice(0, show_list_count);
114115

115116
for (i = 0; i < resultData.length; i++) {

0 commit comments

Comments
 (0)