【发布时间】:2017-08-03 02:45:46
【问题描述】:
Ajax 响应我得到这样的结果:
"students":[{
"student_id":"27",
"job_id":"12",
"128":"8",
"63":"9",
"3":"10",
"weightage":"5.6000"}
,{"student_id":"22",
"job_id":"12",
"128":"5",
"63":"6",
"3":"8",
"weightage":"9.1000"
}]}
从这里我想显示相同的顺序,因为权重(总分)很高,它应该排在最后。
如何按 Desc 过滤? 这是我的代码:
console.log(response['students']);
$.each(response['students'], function(k, student) {
$("#stu"+student.student_id).removeClass('btn-danger reject-student');
$("#stu"+student.student_id).addClass('btn-success select-student');
$("#stu"+student.student_id).text('Student Selected');
});
/*Sorting select-student students at one place starts here*/
var rows = document.querySelectorAll('table tbody tr.sorted');
for (i = 0; i < rows.length; i++) {
if (rows[i].querySelector('span.reject-student')) {
rows[i].closest('tbody').appendChild(rows[i]);
}
}
/*Sorting select-student students at one place ends here*/
【问题讨论】:
-
当您说“过滤器”时,您的意思是“排序”吗?而“desc”的意思是“下降”? (您的问题标题“按 Desc 过滤”听起来您想根据描述字段过滤掉数据......)
-
对不起,我的意思是排序
-
为什么不在服务器端使用 asort 对数组进行排序,然后以 json 格式发送响应。
标签: javascript php ajax filter