我需要一个工作人员的自定义对象,所以我在staff.js中有这个:
function Staff(name, shouldBeRemoved, officeName, dateHired) {
this.name = name;
this.shouldBeRemoved = shouldBeRemoved;
this.officeName = officeName;
this.dateHired = dateHired;
}
我还在office.js中有一个Office的自定义对象:
function Office(name, shouldBeRemoved, staffMembers) {
this.name = name;
this.shouldBeRemoved = shouldBeRemoved;
this.staffMembers = staffMembers;
}
我想将staffMembers属性用作Office中的Staff对象数组。
但是当我尝试将新的staff对象推送到Office对象中的staffMembers数组时,没有任何反应:
staff = new Staff(name, false, officeSelected, d.toDateString());
for (i=0; i<officeArray.length; i++) {
if (officeArray[i].name == officeSelected) {
officeArray[i].staffMembers.push(staff);
}
}
答案 0 :(得分:0)
我的建议是开始使用Typescript,原因是数据类型和类具有清晰的图像。
staff = new Staff(name, false, officeSelected, d.toDateString());
for (i=0; i<officeArray.length; i++) {
if (officeArray[i].name == officeSelected) {
officeArray[i].staffMembers.push(staff);
}
}
这里你应该检查officeArray [i] .name === staff.officeSelected