Skip to Content
0

SAPUI5 , Problem in Calling Sub Functions to Load objects.

Mar 01 at 03:24 PM

25

avatar image

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>
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Christopher Solomon
Mar 01 at 03:51 PM
0

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. =)

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks Christopher, it worked fine..

1