How to sort data in JQuery

允我心安 提交于 2020-03-25 19:13:22

问题


I'm working on a slider which is showing data from the backend. Using the "push" function it is showing slides in the slider according to date. But I need it to show these slides according to date & status.

Firstly show incomplete status (btn-danger), after it show pending status (btn-success), and then completed status (btn-warning).

screenshot of code https://ibb.co/5KJpdrh

full code:

paste.ofcode.org/hmKSwTvaWrjTj3A6rWh464

code:

  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();
    }
}

回答1:


You want to use Array.prototype.sort().

You should pass a compare function to have sort() use your criteria to sort your entries properly.



来源:https://stackoverflow.com/questions/60500585/how-to-sort-data-in-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!