I am creating this Lightning component:
<aura:component>
<aura:attribute name="record" type="Account" />
<aura:attribute name="recordList" type="Account[]" />
...
</aura:component>
..dynamically using...
$A.createComponent(
"c:myComponent",
{
"record": cmp.getReference("v.account"),
"recordList": cmp.getReference("v.accountList")
},
);
I am perfectly able to access the single record but unable to access the record list.
myMethod: function(cmp) {
cmp.get("v.record").Name = "Acme"; // Works
for(var record of cmp.get("v.recordList")) {
record.Name = "Acme"; // Fails
}
}
Accessing the recordList fails with:
Uncaught Action failed: myComponent$controller$myMethod [Cannot add property Name, object is not extensible]
When I console.log
both attributes v.record
is a Map representing an SObject but the recordList
is an obfuscated "thing"
Proxy {0: XI, 1: XI, 2: XI, 3: XI, 4: XI, 5: XI, 6: XI, 7: XI, 8: XI, 9: XI, length: 10}
[[Handler]]
:
Object
[[Target]]
:
Array(10)
0
:
XI {path: Array(3), Ja: "v.recordList.a0246000005mfQzAAI", Kd: false, Ga: a, pb: a, …}
Strangely we could make it work by temporarily assigning/casting it to another attribute of type Account
.
for(var record of cmp.get("v.recordList")) {
cmp.set("v.tempRecord", record);
var temp = cmp.get("v.tempRecord");
temp[field] = number;
cmp.set("v.tempRecord", temp);
cmp.clearReference("v.tempRecord");
}
Why that? A bug? By design?