Skip to Content
avatar image
-1
Former Member

Add resource/file/function to project at runtime

Hi Friends,

let say I have this as a string:

sap.ui.define([], function() {
    "use strict";
    return {
        testFunc: function() {
            alert("function");
        }
    };
});

Now I want to call the above function "testFunc()" from my controller, like:

sap.ui.define(["sap/ui/core/mvc/Controller","...pfad.to.function], 
function(Controller, Function) {
    "use strict";
    return Controller.extend("CONT", {
        onInit: function() ;
           Function.testFunc();
        },
    })
});

But I get only at runtime the above string. So I would think. I create a resource(file.js) at runtime, put the string in there and call the function. But I have no idea how to manage this. I tried with sap.ui.define("functionjs") and then functionjs = string above. And I can find the functionjs in the controller, but I can not call the function testFunc().

Is there a way to manage this?

Rg. Joerg

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Feb 16 at 12:42 PM

    can you tell a bit background?

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 15 at 07:07 PM

    what you are designing?

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 15 at 07:08 PM
    sap.ui.define([],function(){"use strict";return{
            testFunc:function(){
                alert("function");}};});

    if that piece is stored in backend statically. why not just put them in your web app.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Because it can change. You can have several function in there. And this will defined at runtime.