Skip to Content

SAPUI5 , Problem in Calling Sub Functions to Load objects.

Hi,

While going through open SAPUI5, course, week 1, tried following code.

The above code for loading image works fine.

<script>
    var oCore = sap.ui.getCore();
    var oImage3;
    oCore.attachInit(function() {
        alert("Test");
        oImage3 = new sap.m.Image({
            src: "https://sapui5.hana.ondemand.com/resources/sap/ui/documentation/sdk/images/logo_ui5.png"
        }).placeAt("content");
        oImage3.setHeight("100px");
    });
</script> 

....

Now created another function fnPlaceImage() and called via attachInit(),

the Image does not load.

The alert works fine, but image is not loaded, not placed.

Is there any restriction in calling custom functions and loading objects.

Or Is there any constraints in calling functions.

<script>
var oCore = sap.ui.getCore();
var oImage3;
oCore.attachInit(fnPlaceImage());
function fnPlaceImage() {
    alert("Test");
    oImage3 = new sap.m.Image({
        src: "https://sapui5.hana.ondemand.com/resources/sap/ui/documentation/sdk/images/logo_ui5.png"
    }).placeAt("content");
    oImage3.setHeight("100px");
}
</script>
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 01 at 03:51 PM

    In a nutshell...simple answer.....it is because "attachInit" expects an anonymous callback function in there....not a named function. However, just for grins, you can do this...

    oCore.attachInit(fnPlaceImage);



    ....and you should see your image. =)

    Add comment
    10|10000 characters needed characters exceeded