Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJs ng重复多个orderBy和with条件_Javascript_Angularjs_Sorting - Fatal编程技术网

Javascript AngularJs ng重复多个orderBy和with条件

Javascript AngularJs ng重复多个orderBy和with条件,javascript,angularjs,sorting,Javascript,Angularjs,Sorting,我有一份包含就业历史的数据。我的雇佣日期有两个字段: yearTo, monthTo 我需要根据最新的就业日期对就业历史进行正确排序,我可以通过 <tr id="employment_history_" ng-repeat="history in candidate.employmentHistory | orderBy : ['-yearTo','monthTo',] | date:['YYYY', 'MMM'] "> 它工作正常。但我有一个问题。字段monthTo也可以包

我有一份包含就业历史的数据。我的雇佣日期有两个字段:

yearTo, monthTo
我需要根据最新的就业日期对就业历史进行正确排序,我可以通过

<tr id="employment_history_" ng-repeat="history in candidate.employmentHistory | orderBy : ['-yearTo','monthTo',] | date:['YYYY', 'MMM'] ">

它工作正常。但我有一个问题。字段
monthTo
也可以包含值
Present
,而不仅仅是月日期格式
MMM
JAN、FEB-MAR


问题如何排序,我知道我有一个
日期
格式,但我希望列表中的第一个记录是
月份
当前

因此此JSFIDLE可以帮助您朝着正确的方向前进:

这是因为您可以为orderBy指令提供一个谓词数组,就像您在提供的示例中所做的那样。然而,在您的示例中,您仅使用字符串谓词,而还可以使用函数谓词。函数谓词将接收您尝试订购的项目,您可以选择要返回的内容,以便可以使用该值来订购该值

ng-repeat="hist in main.history | orderBy: ['-yearTo', main.orderMonthTo]"

this.orderMonthTo = function(item) {
    if (item.monthTo === 'Present') {
    return -13;
  } else {
    return Number(moment(item.monthTo, 'MMM').format('M'))*-1;
  }
}
关于这一点,可以找到更多信息。
另外,在JSFIDLE中,我使用了这个库来简化日期处理。

您是在问如何按顺序正确地处理Present作为值吗?@yogespatil是的。与datesHere一起使用的是一个JSFIDLE,它应该为您提供正确方向上的一些步骤@GiovaniVercauteren感谢它的成功。您可能想发布您的评论作为答案?