I'm Working on Lightning components I would like to add some values in my App, by its controller (aura:handler)
I'm trying with this :
component.set("v.objetsCamping", tabObjets);
But it doesn't work at all, so the default values of my component is displayed at the end, and only one component.
Here are my codes :
App :
<aura:application >
<aura:attribute type="Camping_Item__c"
name="objetsCamping"/>
<!-- initialisation de valeurs dans le controller -->
<aura:handler name="init"
value="{! this}"
action="{! c.doInit}" />
<aura:iteration items="objetsCamping"
var="obj">
<c:campingListItem />
</aura:iteration>
</aura:application>
AppController.js
({
doInit : function(component, event, helper) {
let tabObjets = [];
tabObjets.push("{'sobjectType':'Camping_Item__c', Name:'tente', Quantity__c:1, Price__c:149.99}");
tabObjets.push("{'sobjectType':'Camping_Item__c', Name:'Sac de couchage', Quantity__c:3, Price__c:25}");
tabObjets.push("{'sobjectType':'Camping_Item__c', Name:'Du miamiam', Quantity__c:42, Price__c:69.4}");
for(let i=0;i<tabObjets.length;i++) {
console.log(tabObjets[i]);
console.log(JSON.stringify(tabObjets[i]));
}
component.set("v.objetsCamping", tabObjets);
}
})
And the component (that I think works well, already worked on fixing issues)
<aura:component >
<!-- mon attribut de component -->
<aura:attribute name="item"
type="Camping_Item__c[]"
required="true"
default="{'sobjectType':'Camping_Item__c',
'Name':'nomObjet',
'Quantity__c':666,
'Price__c':999,
Packed__c:false}"/>
<!-- test d'ajout pour initialiser un item -->
<aura:handler name="init"
value="{!this}"
action="{!c.doInit}"/>
<div>
<h1>Display {! v.item.Name}'s infos : Price, Quantity, Packed ? using an expression.</h1><br />
<ul>
<li>Name : {! v.item.Name}</li><br />
<li>Price : <lightning:formattedNumber value="{! v.item.Price__c}"
style="currency"
currencyCode="EUR"/></li><br />
<li>Quantity : <lightning:formattedNumber value="{! v.item.Quantity__c}"/></li><br />
<li><ui:inputCheckbox aura:id="packed"
label="Packed?"
value="false"/></li>
</ul>
</div>
<div>
<lightning:button label="Packed!"
aura:id="disableButt"
onclick="{! c.packItem }"
disabled="false"/>
</div>
<hr />
</aura:component>
And its controller :
({
doInit: function(cmp) {
},
packItem : function(cmp, event, helper) {
let item = cmp.get("v.item"), // l'objet utilisé par le composant
bouton = event.getSource(), // la source event
checkbox = cmp.find("packed"); // find car on chope du aura:id
console.log('item : ' + JSON.stringify(item));
cmp.set("v.item.Packed__c", true);
console.log(item.Packed__c);
bouton.set("v.disabled", true); // yeaaaah ça fonctionne !!
// desactiver la checkbox
checkbox.set("v.value", true);
}
})
Could you help ? I've read many topics but can't really find my answer ... :!