on 2022 May 12 12:22 PM
Hi Experts,
I am adding sap.m.Link to my controller with dynamic text and on press function.
I have function name onSampleOnePressed:function({window.open("google.com");}); and onSampleTwoPressed:function({window.open("answer.sap.com");});
Here is my code
var aData = [{
text: "Sample1",
actionName: "onSampleOnePressed"
},
text: "Sample2",
actionName: "onSampleTwoPressed"
}
aData.forEach(function(data) {
new sap.m.Link({
text: data.text
press: this.+data.actionName
//press: "this." + data.actionName --error: "this" converted to string not a function
})
});
the dynamic text is shows properly, I'm having trouble how to make press function call dynamically.
When tried to change press to press: data.actionName I'm getting error [TypeError: I.fFunction.call is not a function]
I tried to change to static press to press: this.onSampleTwoPressed to but the sample2 Link same with sample1.
Request clarification before answering.
aData.forEach(function (data) {
new sap.m.Link({
text: data.text
press: (oEvent) => {
const sFunctionName = oEvent.< getYourActionNameHere >
this[sFunctionName]() // expect the function to be on the same controller
}
})
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
do you mean const sFunctionName = oEvent.data.actionName?
what is <getYourActionNameHere>?
I have two action name which is onSampleTwoPressed, and onSampleOnePressed on same controller
I got error on arrow function but I rewrite code to this;
press: function(oEvent) {
const sFunctionName = data.actionName;
this[sFunctionName]();
}and still having an error [this[sFunctionName] is not a function]
| User | Count |
|---|---|
| 17 | |
| 8 | |
| 8 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.