如何根据日期列对Json数据进行排序 [英] How Do I Sort My Json Data Based On Date Column
本文介绍了如何根据日期列对Json数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
LoadLeadCourseRecentActivityList: function () {
var leadCourseId = $("#hdnLeadCourseId").val();
var args = {
leadCourseId: leadCourseId
}
$.ajax({
url: "/Lead/LoadLeadCourseActivityList",
dataType: "json",
type: 'GET',
data: args,
cache: false,
async: false,
success: function (data) {
var leadCourseActivities = '<table id="tblLeadCourseRecentActivities" class="table table-striped table-bordered table-hover table-responsive"><thead><tr class="primary"><th>Activity Type</th><th>Subject</th><th>Description</th><th>Due On</th></tr></thead><tbody>';
var countRA = 1;
debugger;
data = data.sort((function (a, b) {
if (true)return (a[data.DueDate] > b[data.DueDate]) ? -1 : ((a[data.DueDate] < b[data.DueDate]) ? 0 : 1);
//else return (b[data.DueDate] > a[data.DueDate]) ? -1 : ((b[data.DueDate] < a[data.DueDate]) ? 1 : -1);
}));
//data = sortByKey(data, 'data.DueDate');
//data = sortfun(data, 'data.DueDate');
$.each(data, function (i, CourseActivity) {
if (CourseActivity.ActivityTypeCode == null)
CourseActivity.ActivityTypeCode = "";
if (CourseActivity.Subject == null)
CourseActivity.Subject = "";
if (CourseActivity.Description == null)
CourseActivity.Description = "";
if (CourseActivity.DueDate == null)
CourseActivity.DueDate = "";
if (countRA <= 5) {
leadCourseActivities += "<tr><td>" + CourseActivity.ActivityTypeCode + "</td><td>" + CourseActivity.Subject + "</td><td>" + StringConcate(CourseActivity.Description) + "</td><td>"
+ $.format.date(CourseActivity.DueDate, "dd-MMM-yyyy hh:mm a") + "</td></tr>";
}
countRA++;
});
leadCourseActivities += "</tbody></table>";
$('#dvRecentActivity').html(leadCourseActivities);
},
error: function () {
alert('Error while loading lead course activities');
}
});
}
推荐答案
( #hdnLeadCourseId跨度>)VAL();
var args = {
leadCourseId:leadCourseId
}
("#hdnLeadCourseId").val(); var args = { leadCourseId: leadCourseId }
.ajax({
url: / Lead / LoadLeadCourseActivityList,
dataType: json,
类型:' < span class =code-string> GET',
data:args,
cache: false ,
async: false ,
成功:功能(数据){
var leadCourseActivities = ' < table id =tblLeadCourseRecentActivitiesclass = table table-striped table table-hover table-responsive>< thead>< tr class =primary >< th>活动类型< / th>< th>主题< / th>< th>描述< / th>< th>到期< / th>< / tr>< / thead> < TBODY>'跨度>;
var countRA = 1 ;
调试器;
data = data.sort(( function (a,b){
if ( true ) return (a [data.DueDate]> b [data.DueDate])? -1 :(([data.DueDate]< b [data.DueDate])? 0 : 1 );
// else return(b [data.DueDate]> a [data.DueDate ])? - 1:((b [data.DueDate]< a [data.DueDate])?1:-1);
}));
// data = sortByKey(data,'data.DueDate');
// data = sortfun(data,'data.DueDate');
.ajax({ url: "/Lead/LoadLeadCourseActivityList", dataType: "json", type: 'GET', data: args, cache: false, async: false, success: function (data) { var leadCourseActivities = '<table id="tblLeadCourseRecentActivities" class="table table-striped table-bordered table-hover table-responsive"><thead><tr class="primary"><th>Activity Type</th><th>Subject</th><th>Description</th><th>Due On</th></tr></thead><tbody>'; var countRA = 1; debugger; data = data.sort((function (a, b) { if (true)return (a[data.DueDate] > b[data.DueDate]) ? -1 : ((a[data.DueDate] < b[data.DueDate]) ? 0 : 1); //else return (b[data.DueDate] > a[data.DueDate]) ? -1 : ((b[data.DueDate] < a[data.DueDate]) ? 1 : -1); })); //data = sortByKey(data, 'data.DueDate'); //data = sortfun(data, 'data.DueDate');
.each(data, function (i,CourseActivity){
if (CourseActivity.ActivityTypeCode == null )
CourseActivity.ActivityTypeCode = < span class =code-string>;
if (CourseActivity.Subject == null )
CourseActivity.Subject = ;
< span class =code-keyword> if (CourseActivity.Description == null )
CourseActivity.Description = ;
if (CourseActivity.DueDate == null )
CourseActivity.DueDate = < span class =code-string> ;
如果(countRA< = 5 ){
leadCourseActivities + = < tr>< td> + CourseActivity.ActivityTypeCode + < / td>< td> + CourseActivity.Subject + < / td>< td> + StringConcate(CourseActivity.Description)+ < / td>< td>
+
.each(data, function (i, CourseActivity) { if (CourseActivity.ActivityTypeCode == null) CourseActivity.ActivityTypeCode = ""; if (CourseActivity.Subject == null) CourseActivity.Subject = ""; if (CourseActivity.Description == null) CourseActivity.Description = ""; if (CourseActivity.DueDate == null) CourseActivity.DueDate = ""; if (countRA <= 5) { leadCourseActivities += "<tr><td>" + CourseActivity.ActivityTypeCode + "</td><td>" + CourseActivity.Subject + "</td><td>" + StringConcate(CourseActivity.Description) + "</td><td>" +
这篇关于如何根据日期列对Json数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文