contact-list.page.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Component, OnInit } from '@angular/core';
  2. import * as Parse from "parse";
  3. @Component({
  4. selector: 'app-contact-list',
  5. templateUrl: './contact-list.page.html',
  6. styleUrls: ['./contact-list.page.scss'],
  7. })
  8. export class ContactListPage implements OnInit {
  9. searchName: string = '';
  10. contactList: Array<Parse.Object> = [];
  11. ngOnInit() {
  12. this.loadContact();
  13. }
  14. charGroupIndex:any = {}
  15. loadContact() {
  16. const Contact = Parse.Object.extend('Contact');
  17. const query = new Parse.Query(Contact);
  18. query.ascending('firstChar');
  19. if (this.searchName) {
  20. query.contains('name', this.searchName);
  21. }
  22. query.find().then((results) => {
  23. this.contactList = results;
  24. this.contactList.forEach((contact,index)=>{
  25. if(this.charGroupIndex[contact.get("firstChar")] == undefined){
  26. this.charGroupIndex[contact.get("firstChar")] = index
  27. }
  28. })
  29. }, (error) => {
  30. console.error('Error while fetching contacts', error);
  31. });
  32. }
  33. search() {
  34. this.loadContact();
  35. }
  36. }