Argh! Pulling my hair out! I am new to Lightning and I have an app that takes a list Contacts names and phone numbers and allows the user to "Check them in". There is a component that receives and displays all the checked in contacts. I have "Check In" button to pass them to component and it's not successfully passing the contacts. I know this because while the list of items is incrementing I cannot get the contact name to list.
Here is the list component:
<aura:component controller="xsp.ContactController">
<aura:attribute name="contacts" type="xsp.Contact[]"/>
<aura:handler event="xsp:SearchKeyChange" action="{!c.searchKeyChange}"/>
<aura:registerEvent name="selectContactEvent" type="xsp:selectContact"/>
<ul class="list-group">
<aura:iteration items="{!v.contacts}" var="contact">
<li class="list-group-item">
<p>{!contact.Name}</p>
<p>{!contact.Phone}</p>
<a href="#" onclick="{!c.checkIn}" class="btn btn-primary"> Check-In</a>
</li>
</aura:iteration>
</ul>
Here is the controller:
({
doInit : function(component, event) {
var action = component.get("c.findAll");
action.setCallback(this, function(a) {
component.set("v.contacts", a.getReturnValue());
});
$A.enqueueAction(action);
},
searchKeyChange: function(component, event) {
var searchKey = event.getParam("searchKey");
var action = component.get("c.findByName");
action.setParams({
"searchKey": searchKey
});
action.setCallback(this, function(a) {
component.set("v.contacts", a.getReturnValue());
});
$A.enqueueAction(action);
},
checkIn : function(component, event, helper) {
var contact = component.get("v.contact");
var evt = $A.get("e.xsp:selectContact");
evt.setParams({
"contact": contact
});
evt.fire();
},
})
Here is the event:
<aura:event type="APPLICATION" description="Select contact event.">
<aura:attribute name="contact" type="Contact"/>
</aura:event>
Here is the receiving component:
<aura:component >
<aura:attribute name="items" type="xsp.Contact[]"/>
<aura:handler event="xsp:selectContact" action="{!c.handleCheckInEvent}"/>
<div class="col-lg-9 col-md-9 col-sm-12">
<div class="col-lg-12 col-sm-12">
<span class="title">Check-in List:</span>
</div>
<aura:renderIf isTrue="{!v.items.length > 0}">
<div class="col-lg-12 col-sm-12 hero-feature">
<table class="table table-bordered tbl-cart">
<thead>
<tr>
<td>Name</td>
<td class="hidden-xs">Room Number</td>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.items}" var="item">
<tr>
<td>{!item.Name}</td>
<td class="hidden-xs">
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:renderIf>
<aura:renderIf isTrue="{!v.items.length == 0}">
<div class="col-lg-12 col-sm-12 hero-feature">
<p> Nobody is checked in yet.</p>
</div>
</aura:renderIf>
</div>
</aura:component>
Controller:
({
handleCheckInEvent : function(component, event, helper) {
var contact = event.getParam("contact");
var items = component.get("v.items");
if (!items) items = [];
items.push(contact);
component.set("v.items", items);
},
})