javascript - 如何在 JQuery 中对数据进行排序

标签 javascript jquery ejs

我正在开发一个 slider ,它显示来自后端的数据。使用“推送”功能,它可以根据日期在 slider 中显示幻灯片。但我需要它根据日期和状态显示这些幻灯片。

首先显示不完整状态(btn-danger),之后显示待处理状态(btn-success),然后显示完成状态(btn-warning)。

代码截图https://ibb.co/5KJpdrh

完整代码:

paste.ofcode.org/hmKSwTvaWrjTj3A6rWh464

代码:

  function handleSubmit(command) {
    if(command === 'meeting') {

        let meetingFormValue = getMeetingFormValue('.create-meeting-form');
        httpService.post('http://localhost:3000/meeting/create', meetingFormValue)
            .then(response => {
                meetings.push(response);
                setMeetingCarausel();
            }).catch(ex => {
                console.log('Error');
                console.log(ex);
            }) 
        // close the form
        $('.create-meeting-form').stop().slideToggle();
    }else if(command === 'task') {
        //attendees
        const taskFormValue = getTaskFormValue('#createTaskForm');
        httpService.post('http://localhost:3000/meeting/taskList/create', taskFormValue)
            .then(response => {
                tasks.push(response);
                setTasksCarausel();
            }).catch(ex => {
                console.log(ex);
            });

        // close the form
        $('.create-task-form').stop().slideToggle();
    }
}

最佳答案

您想使用Array.prototype.sort() .

您应该传递一个比较函数,让 sort() 使用您的条件对条目进行正确排序。

关于javascript - 如何在 JQuery 中对数据进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60500585/

相关文章:

JavaScript:在 window.location.hash 中获取和设置变量?

javascript - 从 RTE 和 Javascript 开始

javascript - 将匿名 ajax 函数变成常规函数 - 作用域?

javascript - jQuery 通知插件

javascript - 在另一个 ForEach 中创建一个 forEach

javascript - 如何在触发 Rails form_tag 提交操作之前将 MD5 应用于密码?

javascript - 我可以在使用 jQuery Mobile 时通过 URL 传递信息吗?

javascript - jquery延迟淡入循环

javascript - 为 .ejs 设置 Webpack

javascript - ejs和express公共(public)和私有(private)路线的查看页面