getCustomersFromAPICall(): CustomerModel[] {
setTimeout(()=> {
return this.dataFromAPICall = [
{
firstName: 'Nintendo',
lastName: 'Switch',
caseID: 123,
employeeNumber: 1234,
photo: 'https://t4.ftcdn.net/jpg/02/90/27/39/360_F_290273933_ukYZjDv8nqgpOBcBUo5CQyFcxAzYlZRW.jpg',
displayCaseCode: '15',
reasonName: '1C',
frequencyType: FrequencyType.Intermittent,
emailAddress: 'NJ',
networkID: 'ABC',
caseState: CaseState.Open,
requestDate: new Date('12/12/2012'),
startDate: new Date('12/01/1990'),
endDate: new Date('12/01/2000'),
lastUpdated: new Date('1/1/1991')
},
{
firstName: 'Nintendo',
lastName: 'Switch',
caseID: 124,
employeeNumber: 1234,
photo: 'https://t4.ftcdn.net/jpg/02/90/27/39/360_F_290273933_ukYZjDv8nqgpOBcBUo5CQyFcxAzYlZRW.jpg',
displayCaseCode: '15',
reasonName: '1C',
frequencyType: FrequencyType.Continuous,
emailAddress: 'NJ',
networkID: 'ABC',
caseState: CaseState.Closed,
requestDate: new Date('12/12/2012'),
startDate: new Date('12/01/1990'),
endDate: new Date('12/01/2000'),
lastUpdated: new Date('1/1/1991')
},
{
firstName: 'Nintendo',
lastName: 'Switch',
caseID: 125,
employeeNumber: 1234,
photo: 'https://t4.ftcdn.net/jpg/02/90/27/39/360_F_290273933_ukYZjDv8nqgpOBcBUo5CQyFcxAzYlZRW.jpg',
displayCaseCode: '15',
reasonName: '1C',
frequencyType: FrequencyType.Intermittent,
emailAddress: 'NJ',
networkID: 'ABC',
caseState: CaseState.Closed,
requestDate: new Date('12/12/2012'),
startDate: new Date('12/01/1990'),
endDate: new Date('12/01/2000'),
lastUpdated: new Date('1/1/1991')
},
{
firstName: 'Storm',
lastName: 'Kevin',
caseID: 123,
employeeNumber: 1239,
photo: 'https://t4.ftcdn.net/jpg/02/90/27/39/360_F_290273933_ukYZjDv8nqgpOBcBUo5CQyFcxAzYlZRW.jpg',
displayCaseCode: '15',
reasonName: '1C',
frequencyType: FrequencyType.Intermittent,
emailAddress: 'NJ',
networkID: 'ABC',
caseState: CaseState.Open,
requestDate: new Date('12/12/2012'),
startDate: new Date('12/01/1990'),
endDate: new Date('12/01/2000'),
lastUpdated: new Date('1/1/1991')
},
{
firstName: 'Scott',
lastName: 'Summer',
caseID: 124,
employeeNumber: 1235,
photo: 'https://t4.ftcdn.net/jpg/02/90/27/39/360_F_290273933_ukYZjDv8nqgpOBcBUo5CQyFcxAzYlZRW.jpg',
displayCaseCode: '15',
reasonName: '1C',
frequencyType: FrequencyType.Continuous,
emailAddress: 'NJ',
networkID: 'ABC',
caseState: CaseState.Closed,
requestDate: new Date('12/12/2012'),
startDate: new Date('12/01/2000'),
endDate: new Date('12/01/2001'),
lastUpdated: new Date('1/1/2005')
},
{
firstName: 'Victor',
lastName: 'Von Doom',
caseID: 125,
employeeNumber: 1236,
photo: 'https://t4.ftcdn.net/jpg/02/90/27/39/360_F_290273933_ukYZjDv8nqgpOBcBUo5CQyFcxAzYlZRW.jpg',
displayCaseCode: '15',
reasonName: '1C',
frequencyType: FrequencyType.Intermittent,
emailAddress: 'NJ',
networkID: 'ABC',
caseState: CaseState.Open,
requestDate: new Date('12/12/2012'),
startDate: new Date('12/01/2010'),
endDate: new Date('12/01/2005'),
lastUpdated: new Date('1/1/2009')
},
{
firstName: 'Bruce',
lastName: 'Banner',
caseID: 126,
employeeNumber: 1237,
photo: 'https://t4.ftcdn.net/jpg/02/90/27/39/360_F_290273933_ukYZjDv8nqgpOBcBUo5CQyFcxAzYlZRW.jpg',
displayCaseCode: '15',
reasonName: '1C',
frequencyType: FrequencyType.Continuous,
emailAddress: 'NJ',
networkID: 'ABC',
caseState: CaseState.Open,
requestDate: new Date('12/12/2012'),
startDate: new Date('05/01/1990'),
endDate: new Date('01/01/1000'),
lastUpdated: new Date('1/1/2021')
},
{
firstName: 'Peter',
lastName: 'Parker',
caseID: 127,
employeeNumber: 1238,
photo: 'https://t4.ftcdn.net/jpg/02/90/27/39/360_F_290273933_ukYZjDv8nqgpOBcBUo5CQyFcxAzYlZRW.jpg',
displayCaseCode: '15',
reasonName: '1C',
frequencyType: FrequencyType.Continuous,
emailAddress: 'NJ',
networkID: 'ABC',
caseState: CaseState.Closed,
requestDate: new Date('12/12/2012'),
startDate: new Date('08/01/2015'),
endDate: new Date('01/01/1000'),
lastUpdated: new Date('10/1/2022')
}
];
}, 2000);
return this.dataFromAPICall;
}
使用这段代码,我似乎没有得到想要的结果
findEmployee() {
//debugger;
this.searchEmployeeList = this.getCustomersFromAPICall();
如果我删除setTimeout,它可以正常工作,但我想通过添加setTimeout()来测试UI,看看网络是否很慢
2条答案
按热度按时间ruoxqz4g1#
您的代码正确返回空值
如果你用一个小一点的对象来替换这个长的对象,并修剪变量/函数名,你会立刻意识到这是不正确的:
你的函数设置了一个超时,但是 * immediate * 返回
this.data
的 current 值,这就是为什么你什么也得不到--你得到的是this.data
的值,在你向它添加元素之前。您可能需要一个异步函数
查看承诺:如何创建和返回它们。
看看是否可以设计一个异步函数:这可以返回一个承诺,而不是一个实际值。2承诺可以在以后解析为实际值。3例如,这可以在一个由setTimeout控制的延迟之后。
kknvjkwl2#
尝试使用承诺...
如果不想使用async/await,另一个选项是