如何在angularjs中使用唯一过滤器
$scope.students = [
{ name: 'Hai', createdBy:'Thomas', createdOn:'09-09-2016' },
{ name: 'Hal', createdBy:'Thomas', createdOn:'08-09-2016' },
{ name: 'Ho', createdBy:'Bob', createdOn:'07-09-2016', modifiedBy:'Alice', modifiedOn:'07-09-2016' },
{ name: 'Hoan', createdBy:'Thomas1', createdOn:'09-09-2016' },
{ name: 'Hieu', createdBy:'Bob', createdOn:'10-09-2016', modifiedBy:'Thomas1', modifiedOn:'07-09-2016' },
];
我不希望鲍勃因为鲍勃创作被爱丽丝修改为学生姓名' Ho' 和Hieu由Thomas1'
修改我预期的最终输出是最后一次更新的唯一名称
鲍勃没有资格获得这份名单好......
Last updatedBy Last updated date
------------ --------------
Thomas 09-09-2016
Alice 07-09-2016
Thomas1 09-09-2016
答案 0 :(得分:1)
答案 1 :(得分:0)
将您的问题陈述改为技术术语:
如果修改了记录,则修改器将成为创建者。我如何找到独特的创作者?
其中一个解决方案是:
var students = [
{ name: 'Hai', createdBy:'Thomas', createdOn:'09-09-2016' },
{ name: 'Hal', createdBy:'Thomas', createdOn:'08-09-2016' },
{ name: 'Ho', createdBy:'Bob', createdOn:'07-09-2016', modifiedBy:'Alice', modifiedOn:'07-09-2016' },
{ name: 'Hoan', createdBy:'Thomas1', createdOn:'09-09-2016' },
{ name: 'Hieu', createdBy:'Bob', createdOn:'10-09-2016', modifiedBy:'Thomas1', modifiedOn:'07-09-2016' },
];
var studentsTemp = JSON.parse(JSON.stringify(students)); //deep copy
var unique = {};
for(var i = 0; i < studentsTemp.length; i ++){
if(studentsTemp[i].modifiedBy != null){
studentsTemp[i].createdBy = studentsTemp[i].modifiedBy;
}
unique[studentsTemp[i].createdBy] = studentsTemp[i].createdOn;
}
console.log(unique);
将此代码转换为AngularJS
过滤器。