Contains in aura:if : auraIfContains

    sfdcsharepoint.com

    Currently, we don’t have the ability to check contains in aura:if tag Which is most needed features in lightning.

    n

    Component Name:

    n

    AuraIfContains.cmp

     nn   n   n   n   n    n   n   n   n   n	n   {!v.body} n	nn 

    auraIfContainsController.js

    ({n	doInit: function (component, event, helper) {n		var getItems = component.get('v.items');n		var getElement = component.get('v.element'); //It will not match with undefined. n		if ($A.util.isEmpty(getItems) || $A.util.isEmpty(getElement.trim())) {n			component.set('v.isElementFound', false) return;n		};n		var getCurrentElementIndex; //Check type and if it is String then check contains. n		if (typeof getItems == 'string' && typeof getElement == 'string') {n			if (component.get("v.checkCaseSensitivity")) {n				getCurrentElementIndex = getItems.indexOf(getElement);n			} else {n				getCurrentElementIndex = getItems.toLowerCase().indexOf(getElement.toLowerCase());n			}n		} else {n			getCurrentElementIndex = getItems.indexOf(getElement);n		}n		// if getCurrentElementIndex is not equal to -1 it's means list contains this element. n		if (getCurrentElementIndex != -1) {n			component.set('v.isElementFound', true);n		} else {n			component.set('v.isElementFound', false);n		}n	}n})n 

    auraIfContainsApp.app

    n    n    n     nn    String => {!v.items_Str}n    
    Element => {!v.element}n n
    I am String CaseSensitive False ->n {!v.element} n n
    I am String CaseSensitive True ->n {!v.element} n n
    n n
    Array are always caseSensitive irrespective sensitivity flag.n
    I am Array CaseSensitive False ->n {!v.element} n n n
    I am Array CaseSensitive True -> n {!v.element} n n
    n

    Like our Facebook page and get the latest updates. Do let us know if you want to see the blog on the specific topic.

    n

    #Javascript #Lightning

    Leave a Reply

    Your email address will not be published. Required fields are marked *