Skip to Content
-1

Add resource/file/function to project at runtime

Feb 15 at 06:00 PM

105

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Jun Wu Feb 16 at 12:42 PM
0

can you tell a bit background?

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi, Jun

it should working like this.

The developer has an editor. In this editor he is writing the function code. Like above. When he is finished, the code is written to the backend. When the application is starting, the code will fetched from the backend and proceed in frontend. So only at this time I know the code and have to run it dynamically. An furthermore, I need the possibility to debug. So I need to load the whole script file.

0
Former Member

what's the point?

0
Jun Wu Feb 15 at 07:07 PM
0

what you are designing?

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Feb 15 at 07:08 PM
0
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.

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

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

0