Posts

To find array index of complex

<aura:component >          <aura:handler name="render" value="{!this}" action="{!c.myAction}"/>     <aura:attribute name="objs" type="Object[]" /> </aura:component> ({ myAction : function(component, event, helper) { var studentsArray =      [     {     "rollnumber": 1,     "name": "dj",     "subject": "physics"    },    {    "rollnumber": 2,   "name": "tanmay",   "subject": "biology"    },   {    "rollnumber": 3,    "name": "amit",    "subject": "chemistry"    },                   ];            console.log('studentsArray'+JSON.stringify(studentsArray[0]));         console.log(studentsArray[0].rollnumber);   console.log(studentsArray[0].name...

javascript to search array of object

var studentsArray = [ { "rollnumber" : 1 , "name" : "dj" , "subject" : "physics" }, { "rollnumber" : 2 , "name" : "tanmay" , "subject" : "biology" }, { "rollnumber" : 3 , "name" : "amit" , "subject" : "chemistry" }, ]; function functiontofindIndexByKeyValue ( arraytosearch , key , valuetosearch ) { for ( var i = 0 ; i < arraytosearch . length ; i ++) { if ( arraytosearch [ i ][ key ] == valuetosearch ) { return i ; } } return null ; } var index = functiontofindIndexByKeyValue ( studentsArray , "name" , "tanmay" ); alert ( index ); function getIndex ( val ) { for ( var i = 0 ; i < imageList . length ; i ++) { if ( imageList [ i ] ...

Array to push element to array

mpex_app.app <aura:application extends="force:slds">   <c:mpex1></c:mpex1> </aura:application> CMP <aura:component>   <aura:attribute name="objs" type="Object[]" />   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />   <table>     <tr>       <th>Product</th>       <th>Price</th>     </tr>     <aura:iteration items="{!v.objs}" var="obj">       <tr>         <td>{!obj.product}</td>         <td>{!obj.price}</td>       </tr>     </aura:iteration>   </table>   <!-- component B -->   <lightning:button variant="brand" label="Add another" title="Brand action" onclick="{! c.handleClick }" /> </aura:component> JS ({ ...

Multiple Checkboxex with default as true

toggle_smle_app.app <aura:application extends="force:slds">     <aura:attribute name="allaccounts" type="List" default="[ { BillingCity: 'Denver' }, { BillingCity: 'Ontario' }, { BillingCity: 'San Francisco' } ]" />     <aura:attribute name="selectedCities" type="List" default="[]" />     <aura:iteration var="a" items="{!v.allaccounts}" indexVar="indx">         <ui:inputCheckbox aura:id="checkbox"                           value="true" text="{!a.BillingCity}"                           name="{!indx}"                           label="{!a.BillingCity}"                           change="{!c.selectoptionvalue}"/>     </aura:iterat...

Onclick of button iterate and display map from server to client side controller

Aura Class public class SampleAuraController {   @AuraEnabled     Public static Map<string, List<string>> getMap(){         Map<String, List<string>> mapObj = new Map<String, List<string>>();         List<string> fruits = new List<String>{'Apple', 'Orange', 'Banana', 'Grapes'};         List<string> vegetables = new List<String>{'Cabbage', 'Carrot', 'Potato', 'Tomato'};         mapObj.put('Fruits', fruits);         mapObj.put('Vegetables', vegetables);         return mapObj;     } } c:SampleAuraController <aura:component controller="SampleAuraController">     <aura:attribute name="mapValues" type="object" />     <div class="slds-m-around_xx-large">         <div class="slds-box slds-theme_default"> ...

Onclick of button through iteration shows index

test_a.app <aura:application extends="force:slds">    <ul>         <aura:iteration items="[a1,a2,a3,a4]" var="product" indexVar="index">             <li onclick="{!c.ShowDataOnClick}" data-row-index="{!index}">                 <p>{!product}</p>                           </li>         </aura:iteration>     </ul> </aura:application> ({         ShowDataOnClick: function(component, event, helper) {            var index = event.currentTarget.dataset.rowIndex;             console.log(index);             console.log(event.currentTarget.dataset.rowIndex);         }     }) O/p [a1...

Attributes

Label Hidden Used to hide the label                    <lightning:input type="number" label="number" variant = "label-hidden" name="aNumberInputField"/> <aura:component >     <lightning:recordEditForm objectApiName="Account">         <lightning:messages />             <div class="slds-grid">                <div>                 <div class="slds-col slds-size_1-of-3">                    <lightning:input type="number" label="number" variant = "label-hidden" name="aNumberInputField"/>                 </div>                <div class="slds-col slds-size_1-of-3">           ...