使用 underscorejs 转换集合的更好方法
Better way to transform a collection using underscorejs
我只是想用空字符串替换无效日期。我正在遍历一组对象,但每当我尝试使用 _.each()
时,我都会迷路。如果有人能告诉我一种遍历列表中所有 fieldsToCheck
项的方法,那就太棒了。
massage.removeBadDates = function(data){
var fieldsToCheck = [
"partsLeadTime",
"statusDate",
"targetDate",
"revisedTargetDate",
"quoteDate",
"dispositionDate",
"serviceDate",
"finalDate",
"receivedDate"]
var newData = []
_.map(data, function(value, index, list){
newData.push(value)
//single
if (list[index].partsLeadTime == "1900-01-01T00:00:00"){
newData[index].partsLeadTime = ""
}
});
return newData
};
您非常想要这样的东西:
_.each(fieldsToCheck(function(field) {
if (list[index][field] == "1900-01-01T00:00:00") {
newData[index][field] = ""
}
});
我只是想用空字符串替换无效日期。我正在遍历一组对象,但每当我尝试使用 _.each()
时,我都会迷路。如果有人能告诉我一种遍历列表中所有 fieldsToCheck
项的方法,那就太棒了。
massage.removeBadDates = function(data){
var fieldsToCheck = [
"partsLeadTime",
"statusDate",
"targetDate",
"revisedTargetDate",
"quoteDate",
"dispositionDate",
"serviceDate",
"finalDate",
"receivedDate"]
var newData = []
_.map(data, function(value, index, list){
newData.push(value)
//single
if (list[index].partsLeadTime == "1900-01-01T00:00:00"){
newData[index].partsLeadTime = ""
}
});
return newData
};
您非常想要这样的东西:
_.each(fieldsToCheck(function(field) {
if (list[index][field] == "1900-01-01T00:00:00") {
newData[index][field] = ""
}
});