I have a component that contains a list of associated selection lists, consisting of 1 level, 2 level, 3 level. The second and third levels have a list of checkboxes, which the user can flag. This data is passed to an apex class and saved in the corresponding fields. So far everything is ok, the problem is that I should be able to keep the checkbox flagged on the levels based on the data saved by the user even when I close and reopen the component. but so far I haven't been able to achieve this result, can anyone help me? I attach part of the code.
<aura:if isTrue="{!v.selectedSecondLevel == sett}">
<ul>
<aura:iteration items="{!v.secondSet}" var="sett2">
<li>
<div class="livello2 slds-p-left_medium">
<input type="checkbox"
aura:id="2livello" id="{!'checkbox_' + sett2}"
onchange="{!c.selectSecondLevel}"
data-livello1="{!sett}" data-livello2={!sett2}"
label="{!sett2}" />
<label for="{!'checkbox_' + sett2}" class="slds-m-left_small">{!sett2}</label>
</div>
Controller:
showSecondLevel: function(component, event, helper) {
var accountId = component.get("v.recordId");
var livello1 = event.currentTarget.dataset.livello1;
var previouslySelected = component.get("v.selectedSecondLevel");
component.set("v.selectedFirstLevel", livello1);
component.set("v.selectedSecondLevel", livello1);
helper.getSecondLevel(component, livello1);
helper.initCheckbox(component);
},
HELPER:
initCheckbox: function(component, event) {
var actionFigli = component.get("c.PopolaCheckFigli");
actionFigli.setParams({ AccId: component.get("v.recordId") });
actionFigli.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var figli = response.getReturnValue();
console.log("Figli:", figli);
component.set("v.figli", figli); // Imposta la lista dei figli nel componente
// Itera sui valori delle checkbox
var checkboxes = component.find("2livello");
console.log("checkbox: " ,checkboxes);
}
});
From the apex class method PopolaCheckFigli, I get the value of the data previously saved in the database. What I need to do is take this data and flag the corresponding checkbox.
In the console log I see that for the 2nd level value this is printed: checkbox: Proxy(Array) {0: a, 1: a, 2: a} but I cannot access the values inside it, making it impossible for me to obtain the result which I'm trying to achieve.I'm definitely doing something wrong and there is probably 1 simpler method, can anyone help me? Thank you