If you are creating Lightning component and enabling LockerService (Summer 16 pre-release), almost all of the functionality will be broken, specially if you are using HTML tags.
I have a very simple use case which should work but not working. Any help is appreciate.
I have one list which have 1 item. Onclick of this item, i am inserting 1 more item in this list. (Code is as given below.)
Lightning application t1.app
<aura:application>
<ul aura:id="ul">
<li aura:id="l1" onclick="{!c.addNewLi}"> A </li>
</ul>
</aura:application>
t1Controller.js
({
addNewLi: function(cmp) {
console.log('You clicked on 1st LI.');
// Below 2 debug log will see later
console.warn(document.getElementById("l1"));
console.warn(document.getElementById("l2"));
$A.createComponents(
[["aura:html", {"tag":"li", "body":"B", "HTMLAttributes":{"id":"l2"}}]],
function(components, status){
if (status === "SUCCESS") {
var li = components[0];
console.log(li);
var ul = cmp.find("ul");
var ulBody = ul.get("v.body");
ulBody.push(li);
console.log(ulBody);
ul.set("v.body", ulBody);
alert('2nd LI is added.');
}
}
);
}
})
As if you click on 1st item, no error is coming and if you check console.log(), it show 2 item but on ui level nothing is changed.
After some debugging, i modify the js controller code little bit and now 2nd li is added but now stuck on 2nd problem. Now 1st lets check the modified controller
({
addNewLi: function(cmp) {
console.log('You clicked on 1st LI.');
// Below 2 debug log will see later
console.warn(document.getElementById("l1"));
console.warn(document.getElementById("l2"));
$A.createComponents(
[["aura:html", {"tag":"li", "body":"B", "HTMLAttributes":{"id":"l2"}}]],
function(components, status){
if (status === "SUCCESS") {
var li = components[0];
console.log(li);
var ul = cmp.find("ul");
var ulBody = []; //ul.get("v.body");
ul.get("v.body").forEach(function(item, index){
ulBody.push(item);
});
ulBody.push(li);
console.log(ul);
ul.set("v.body", ulBody);
alert('2nd LI is added.');
}
}
);
}
})
Now again go to lightning app and click on 1st item and this time 2nd item will be added. But now lets talk about 2nd problem. For that see the warning message on console in browser
When you 1st time ckick on 1st item A, you see object and null which is correct as 2nd li is not inserted till now.
But if you again click on 1st item, it show object & undefined. Now why undefined is coming as if you see the li is inserted.
And i am in the same component and not trying to access parent, so i should get object instead of undefined. Anyone can help me on this.