0
串在我的TypeScript
我有這個類:檢查對象包含打字稿
export class PhoneBookPerson {
Email: string;
Name: string;
Phonenumber: string;
ProfileImg: string;
Department: string;
JobTitle: string;
Username: string;
}
我不知道我怎麼能檢查是否有任何屬性包含特定值。
let $SearchTerm = target.val();
function RetrievedUsers(sender: any, args: any) {
for (let i = 0; i < users.get_count(); i++) {
let user = users.getItemAtIndex(i);
let person = new PhoneBookPerson();
person.Name = user.get_loginName();
person.Email = user.get_email();
person.Username = user.get_loginName();
person.JobTitle = user.get_title();
<-- search of person contains value from $SearchTerm
usermatch.push(person);
}
}
哪裏是'$ SearchTerm'變量?你想與人的至尊屬性匹配什麼樣的價值? –
'$ SearchTerm包含任何形式的用戶輸入值.'我想看看Person中的任何屬性是否包含該值 –
只需使用Object.keys(person).some(k => k.includes($ SearchTerm )) – AlexG