Javascript排序回调 [英] Javascript sort callback
本文介绍了Javascript排序回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要对Javascript项目进行排序,我正在使用 sort
这样的函数:
I need to sort a big list of Javascript items and I'm using the sort
function like this:
var sorted_list = non_sorted.sort(function(a,b){
// Sort stuff here
});
我想做的是在排序时调用函数
功能已完成。
What I'd like to do is to call a function when the sort
function is done.
当排序时,是否可以添加回调函数来排序或触发事件
结束了?
推荐答案
你过度复杂了。 sort
方法不是异步的,因此您不需要回调或事件。只需将代码放在调用 sort
的代码之后:
You are overcomplicating it. The sort
method isn't asynchronous, so you don't need a callback or an event. Just put your code after the code that calls sort
:
var sorted_list = non_sorted.sort(function(a,b){
// comparer
});
// The code just continues here after the sort
这篇关于Javascript排序回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文