Hello,
Type Script
in Ionic2
application:
How to get item from this.myList
of check-boxes
by another element. If I add elements to private myList: any = [];
this way:
this.myList.push({ id: i, name: myName, UID: obj.UID },);
where id: i
is a loop iteration number, name: myName
is a username, and UID: obj.UID
is a non sequential specific number, then myList
content should be:
id| myName | UID
-------------------
0 | sally | 345
1 | vikram | 5487
2 | kim | 12
3 | roy | 2134
Goal is to find ID: obj.ID
by myName
value. For example get UID
value: 12 by myName
: kim
it is undefined
and does not returns existed value, this way :
findByName() {
const found = this.myList.find(({ name }) => this.searchName === name);
if (found) {
return found.UID;
} else {
return null;
}
}
then I’ve tried differently, with adding: this.myList[myName] = { id: i, name: myName, UID: obj.UID };
to list: myList: {[name: string]: { id: number, name: string, UID: string }} = {};
but it same result undefined
:
findByName(searchName: string) {
const found = this.myList[searchName];
if (found) {
return found.UID;
} else {
return null;
}
}