0

I am trying to add items to the lightning tree component through the controller js file on the click of a button. I already have all the data pulled in on the load event. What happens now is it just loads the labels expanded with no items. Here is my js code:

    loadSuitesForMDU : function(component, event, helper) {     
    var streetName = event.getSource().get("v.title");
    var city = event.getSource().get("v.name");
    var selectedMduUnits = component.get("v.mduInfoForChartAndRightContent");        
    var unitsToFilter = selectedMduUnits.filter(x => { return x.Name === streetName && x.sumchans__city__c === city; });
    var filterNn = unitsToFilter.filter(x => { return x.sumchans__accountNumber__c === undefined && x.sumchans__contactNumber__c === undefined; });
    var filterCc = unitsToFilter.filter(x => { return x.sumchans__accountNumber__c === undefined && x.sumchans__contactNumber__c != undefined; });
    var filterAa = unitsToFilter.filter(x => { return x.sumchans__status__c === 'On-billing'; });
    var items = [{
        "label": "Never",
        "expanded": true,
        "items": [filterNn]
    }, {
        "label": "Active",
        "expanded": true,
        "items": [filterAa]
    }];        
    component.set("v.suitesList",items);     

},

Here is the markup:

<lightning:tree items="{! v.suitesList }" header="Suites"/>

enter image description here

0

Array filter method always returns a new Array. You are assigning nested array to "items" change "items" : [filterNn] to "items" : filterNn and "items" : [filterAa] to "items" : filterAa

| improve this answer | |
  • @Nitesh tried it still the same, not showing any data. – sumchans Jan 25 '19 at 4:52
  • @Sumchans have you tried console logging filterNn and filterAa? – Nithesh N Jan 25 '19 at 5:06
  • I got the original post edited with pic from console log – sumchans Jan 25 '19 at 5:11
  • @Sumchans Does filterNn elements have "label" key in them? – Nithesh N Jan 25 '19 at 5:39
  • no they don't have label – sumchans Jan 25 '19 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.