You need to sign in to do that
Don't have an account?
Handle Actions with Controllers: why not "v.item.Packed__c"?
What is the allowed syntax for v.attribute notation in controllers?
I found the same solution as @Jeff Hansen, but I'm curious about WHY. Why do we have to do
Instead of just doing
I found the same solution as @Jeff Hansen, but I'm curious about WHY. Why do we have to do
var a = component.get("v.item");
a.Packed__c = true;
component.set("v.item",a)
a.Packed__c = true;
component.set("v.item",a)
Instead of just doing
component.set("v.item.Packed__c",true)
to get the correct answer here?
I can't find documentation about this.
Thank you.
PS: is there a way to include code blocks in these questions and answers?
Well you can do the task by both the ways, but the best way is - as here you have the advantage to update multiple fields easily within javascript and you have to update on the page only once using component.set() method.
Whereas here - You have to write the same statement for each field of object and the JS is communicating with page again and again.
So, this is a more better approach as well as an easy one.
Thanks,
Rahul Malhotra
I could do the below and it was alright.
<p>
<lightning:input type="checkbox"
checked="{!v.item.Packed__c}" label="Packed"/>
</p>
<div>
<lightning:button label="Packed?" name='myButton' onclick="{!c.packItem}"/>
</div>
Controller:
({
packItem: function(component, event, helper) {
var btnClicked=event.getSource();
component.set("v.item.Packed__c", true);
}
})