【发布时间】:2022-01-06 19:24:19
【问题描述】:
我有一个自定义项目:
export class PartsChildInfo {
name: string;
materialName: string;
thickNess: number;
}
export class PartGroupInfo
{
materialName: string;
thickNess: number;
}
例如,我有一个列表项 PartsChildInfo:
list : PartsChildInfo = [
{ Name = "GA8-0608" , MaterialName = "SS" , ThickNess = 1 };
{ Name = "05F1-051" , MaterialName = "SUS" , ThickNess = 2 };
{ Name = "2B73-002" , MaterialName = "AL" , ThickNess = 3 };
{ Name = "01-20155" , MaterialName = "SS" , ThickNess = 1 };
{ Name = "02MEG099" , MaterialName = "SUS" , ThickNess = 2 }; ]
我想从列表中获取与 MaterialName、ThickNess 相同的列表:
testChildList : PartGroupInfo = [
{ MaterialName = "SS" , ThickNess = 1 };
{ MaterialName = "SUS" , ThickNess = 2 };
{ MaterialName = "AL" , ThickNess = 3 }; ]
我正在使用 Typescript Angular
我试过了
testChildList : PartGroupInfo[] = [];
for (let i = 0; i < list.length; i++) {
let targeti = list[i];
for (let j = 0; j < this.testChildList.length; j++) {
let targetj = this.testChildList[j];
if (targeti.materialName != targetj.materialName && targeti.thickNess != targetj.thickNess) {
let item = new PartGroupInfo();
item.materialName = targeti.materialName;
item.thickNess = targeti.thickNess;
this.testChildList.push(item);
}
}
}
但返回列表为空。我该如何解决?
【问题讨论】:
-
什么是
data[j]? -
@YongShun 我是 sr,我在帖子中编辑但仍然返回空列表
-
我猜
this.testChildList.push(item);应该是testChildList.push(item); -
@N.F.谢谢,但它仍然返回空列表
-
你要返回哪个变量?
标签: angular typescript list listobject