我想按从最早到最新的顺序对对象数组进行排序。我最初使用momentjs库执行此操作,但它确实有效,但是现在不赞成使用我使用的方法。
首先,我尝试将输入时间设为标准时间(例如0500),然后使用该属性对其进行排序。但是我在将这个新的标准时间和所有其他属性推入计划数组时遇到了麻烦。
我当时在考虑array.sort()
先按数字排序am/pm
然后再按数字排序。我不知道如何去了解它,因为我必须处理am
和pm
app.js
.controller('SchedulerController', schedulerCtrl);
function schedulerCtrl() {
this.plans = [
{
displayTime: '05:00pm',
duration: '30',
task: 'Team meeting',
},
{
displayTime: '06:00pm',
duration: '60',
task: 'Watch favorite TV show'
}
];
}
schedulerCtrl.prototype.addNewTask = function() {
var that = this;
that.plans.push(that.user);
that.user = '';
}
可以使用自定义过滤器,
<p>{{item | orderBy:sortItemsAccording2Time}}</p>
var App = Angular.module('myApp',[])
App.filter('sortItemsAccording2Time',function(input,scope){
//logic here (service dependency can also be used for orderby service by just injecting the respective service which serves the job)
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句