Chris Chris - 7 months ago 60
Javascript Question

Get expanded attribute JQuery

I got this code snippet:

onAfterRendering: function() {
//#oTree-TreeCont: oTree -> ID des Tree, -TreeCont -> Konstante die den Content Bereich anspricht
$('#oTree-TreeCont ul li').click(function(){
var $aria = $(this).attr("aria-expanded");
if($aria){ //Element wurde aufgeklappt
alert($aria);
var clickedNode = $(this).attr("id"); //Erfrage ID
//Lade alle Childs der 'clickedNode'
sap.ui.getCore().byId("idOrganisation_Home1").getController().loadChildNodes(clickedNode);
}
});

}


I want, that if the Tree (SAPUI5) is expanded a method should load the child elements of this node. The problem is, it alerts "true", but also "false".

Why could this happen? This part
if($aria){ }
should test if the value is true, but also when it is false, the body of the
if
statement is executed, why?

Thanks for every help:)

Answer

Because currently the attribute value is treating as a string value, not the boolean value. You need to check like this,

if($aria=="true")