You need to sign in to do that
Don't have an account?
Joe Xu 7
Cannot read property 'apply' of undefined
Hi, I'm doing Trailhead course: Lightning Components Basics (Input Data Using Forms) and hitting below error:
"Something has gone wrong. Action failed: aura$iteration$controller$itemsChange [Cannot read property 'apply' of undefined] Failing descriptor: {aura$iteration$controller$itemsChange}. Please try again."
Here is my campingList.cmp:
I can see the error happens in below code within campingList.cmp:
"Something has gone wrong. Action failed: aura$iteration$controller$itemsChange [Cannot read property 'apply' of undefined] Failing descriptor: {aura$iteration$controller$itemsChange}. Please try again."
Here is my campingList.cmp:
<aura:component > <aura:attribute name="newItem" type="Camping_Item__c" default="{ 'sobjectType': 'Camping_Item__c', 'Name': '', 'Quantity__c': 0, 'Price__c': 0, 'Packed__c': false}"/> <aura:attribute name="items" type="Camping_Item__c[]"/> <div aria-labelledby="newcampingitemform"> <!-- BOXED AREA --> <fieldset class="slds-box slds-theme--default slds-container--small"> <legend id="newcampingitemform" class="slds-text-heading--small slds-p-vertical--medium"> Add Camping Item </legend> <!-- CREATE NEW CAMPING ITEM FORM --> <form class="slds-form--stacked"> <div class="slds-form-element slds-is-required"> <div class="slds-form-element__control"> <ui:inputText aura:id="name" label="Name" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Name}" required="true"/> </div> </div> <div class="slds-form-element slds-is-required"> <div class="slds-form-element__control"> <ui:inputNumber aura:id="quantity" label="Quantity" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Quantity__c}" required="true"/> </div> </div> <div class="slds-form-element"> <div class="slds-form-element__control"> <ui:inputCurrency aura:id="price" label="Price" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Price__c}" required="true"/> </div> </div> <div class="slds-form-element"> <div class="slds-form-element__control"> <ui:inputCheckbox aura:id="packed" label="Packed" class="slds-input" labelClass="slds-form-element__label" value="{!v.newItem.Packed__c}"/> </div> </div> <div class="slds-form-element"> <ui:button label="Create Camping Item" class="slds-button slds-button--brand" press="{!c.clickCreateNewCampingItem}"/> </div> </form> <!-- / CREATE NEW CAMPING ITEM FORM --> </fieldset> <!-- / BOXED AREA --> </div> <!-- /SHOW LIST OF CAMPING ITEM --> <div class="slds-card slds-p-top--medium"> <header class="slds-card__header"> <h3 class="slds-text-heading--small">Camping Items</h3> </header> <section class="slds-card__body"> <div id="list" class="row"> <aura:iteration items="{!v.items}" var="i"> <c:campingListItem item="{!i}"/> </aura:iteration> </div> </section> </div> <!-- /SHOW LIST OF CAMPING ITEM --> </aura:component>And below is campingListItem.cmp:
<aura:component> <aura:attribute name="item" type="Camping_Item__c"/> <p>Name: <ui:outputText value="{!v.item.name}"/> </p> <p>Price: <ui:outputCurrency value="{!v.item.Price__c}"/> </p> <p>Quanity: <ui:outputNumber value="{!v.item.Quantity__c}"/> </p> <p>Packed: <ui:outputCheckbox value="{!v.item.Packed__c}"/> </p> </aura:component>
I can see the error happens in below code within campingList.cmp:
<aura:iteration items="{!v.items}" var="item"> <c:campingListItem item="{!item}"/> </aura:iteration>And once I replace it with below code, the error doesn't happen any more. Can someone help check what's wrong with my nest component code. Thanks!
<aura:iteration items="{!v.items}" var="item"> <aura:attribute name="item" type="Camping_Item__c"/> <p>Name: <ui:outputText value="{!item.name}"/> </p> <p>Price: <ui:outputCurrency value="{!item.Price__c}"/> </p> <p>Quanity: <ui:outputNumber value="{!item.Quantity__c}"/> </p> <p>Packed: <ui:outputCheckbox value="{!item.Packed__c}"/> </p> </aura:iteration>
campingListController.js:
campingListHelper.js:
Thanks.
Try to wrap it your iteration with span it will solved,
use below code,
hopw this will help you,
Mark BestANSWER if its work for you.
Thanks
karthik