SHARE
TWEET

Untitled

a guest Jul 12th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div class="slds-scrollable_y" style="height:300px">
  2.     <template
  3.         for:each={contacts.data}
  4.         for:item="contact"
  5.     >
  6.         <div
  7.             class="slds-p-top_small"
  8.             key={contact.Id}
  9.             onclick={handleContactClick}
  10.             id={contact.Id}
  11.         >
  12.             <ul>
  13.                 <li class="slds-item">
  14.                     {contact.Name}
  15.                 </li>
  16.                 <li class="slds-item">
  17.                     {contact.Phone}
  18.                 </li>
  19.             </ul>
  20.  
  21.             <div class="slds-p-top_small">
  22.                 <hr>
  23.             </div>
  24.         </div>
  25.     </template>
  26. </div>
  27.      
  28. import { LightningElement, track, wire } from 'lwc';
  29. import searchContacts from '@salesforce/apex/ContactsListController.searchContacts'
  30. export default class ContactList extends LightningElement {
  31.     @track searchTerm = ''
  32.     @track contacts
  33.     @track selectedContact = ''
  34.     @wire(searchContacts, { searchTerm: '$searchTerm' })
  35.     loadContacts(result) {
  36.         this.contacts = result
  37.     }
  38.  
  39.     handleContactSearch(event){
  40.         //Debounce the method
  41.         window.clearTimeout(this.delayTimeout)
  42.         const searchTerm = event.target.value;
  43.         // eslint-disable-next-line @lwc/lwc/no-async-operation
  44.         this.delayTimeout = setTimeout(() => {
  45.             this.searchTerm = searchTerm
  46.         }, 300)
  47.     }
  48.  
  49.     handleContactClick(event){
  50.         // eslint-disable-next-line no-console
  51.         console.log(event.target.value);
  52.         this.selectedContact = event.target.value;
  53.     }
  54.  
  55.     checkIfEmpty(){
  56.         // eslint-disable-next-line eqeqeq
  57.         return this.selectedcontact == '';
  58.     }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top