我正在使用一个滑块,该滑块正在显示来自后端的数据。使用“状态:1,DueDate:1”功能。它以相反的顺序显示,但是我需要它根据先显示“ pending(btn-success)”然后显示“ completed(btn-warning)”的状态来显示这些幻灯片。
注意:滑块也有(必须先显示“ btn-danger”),它没有状态
首先显示(btn-danger),然后显示状态=待定(btn-成功),然后显示状态=已完成(btn-警告)。
滑块的屏幕截图:https://ibb.co/jJqLbQQ
控制器代码:
var renderListOfMeetings = async function(req, res) {
try {
checkRoles(req);
let meetings = await Meeting.find({}).sort({ status: 1, date: 1 });
let tasks = await Task.find({}).sort({ status: 1, dueDate: 1 });
res.render("meeting", {
title: "Meetings",
pdfUrl: config.pdfUrl,
isAdmin: req.roleAdmin,
sectionBCommittee: [],
meetings: meetings,
tasks: tasks
});
} catch (ex) {
console.log(ex.message);
}
};
前端代码:
function setTasksCarausel() {
html = '<div class="carousel-inner no-padding">';
let tasksCopy = utils.setSliders(Array.from(tasks));
tasksCopy.map((tasks, index) => {
html += `<div class="item ${index === 0 ? 'active' : ''}">`;
tasks.map(t => {
html += `
<div class="col-md-3 col-sm-6 col-xs-12 pending-task-btn" onclick="handleClickTaskItem('${t._id}')">
<span href="" class="btn ${t.status === 'completed' ? 'btn-warning' : (new Date(t.dueDate) < new Date() ? 'btn-danger' : 'btn-success')} btn-lg dashboard-icon" style="width: 200px; height: 150px;">
<p style="padding-top: 10px; font-size: 20px; font-weight: bold;">${t.type}</p>
<p style="padding-top: 12px; font-size: 20px; font-weight: bold;">${utils.convertDate(t.dueDate)}</p>
<p style="padding-top: 10px; font-size: 20px; font-weight: bold;">( ${t.status } )</p>
</span>
</div>
`;
});
html += `</div>`;
})
function setMeetingCarausel() {
let meetingsCopy = utils.setSliders(Array.from(meetings));
let html = '<div class="carousel-inner no-padding">';
meetingsCopy.map((meeting, index) => {
html += `<div class="item ${index === 0 ? 'active' : ''}">`;
meeting.map(m => {
let className = m.status === 'completed' ? 'btn btn-warning btn-lg dashboard-icon' : 'btn btn-success btn-lg dashboard-icon'
html += `
<div class="col-md-3 col-sm-6 col-xs-12" onclick="handleClickMeetingItem('${m._id}')">
<span href="" class="${className}" style="width: 200px; height: 150px;">
<p style="padding-top: 10px; font-size: 19px; font-weight: bold;">${m.subject}</p>
<p style="padding-top: 12px; font-size: 19px; font-weight: bold;">${utils.convertDate(m.date)}</p>
<p style="padding-top: 10px; font-size: 19px; font-weight: bold;">( ${m.status} )</p>
</span>
</div>
`;
});
html += `</div>`;
})
完整的屏幕截图:https://ibb.co/SKVh4Jp
let meetings = await Meeting.find({}).sort({ status: 1, date: -1 });
let tasks = await Task.find({}).sort({ status: 1, dueDate: -1 });
请尝试以上
将-1用于最新文档。