Skip to Content

Alternative to arrow-function =>

screenshot-36-li.jpgscreenshot-37.pngscreenshot-38.pngHi guys,

So I have the following problem: We are developing an app. In that app you can look for certain objects by typing the ID of that object. My goal is that if you type in the number, but accidentally add a space (' ') or anything additional (letters etc.), which the number itself doesn't contain, it should still find the number and show the object to you.

Now our SAPUI Verison doesn't support ES6 so the arrow function doesn't work for me here. Is there any alternative to that so it works?

First screenshot you can see the code.

Second Screenshot is the dialog to type in and look for a certain number.

Third screenshot than is the object and the number.

I hope you can help me. Thanks!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Dec 19, 2018 at 08:35 PM

    Hi Tatyana,

    Check this blog, which will remove the eslint errors from webide

    https://blogs.sap.com/2017/11/01/next-generation-javascript-in-ui5-using-sap-web-ide/

    BR,

    Mahesh

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 19, 2018 at 09:57 PM

    > Now our SAPUI Verison doesn't support ES6 so the arrow function doesn't work

    Sure, you can always replace arrow functions with function declarations like this:

    arrsText.forEach(function(item, index) {
      // ...
    }.bind(this));

    But the error indication in the code editor is not due to the lack of support by the framework but due to the missing ESlint parameter in your project settings which needs to be added:

    With ES6 syntax, you now have to transpile the code before deploying as explained by Wouter's blog post (in case the target browser is not being actively developed, such as IE11) or apply this workaround to deploy the app without transpiling it.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 19, 2018 at 10:19 PM

    In addition to my previous answer, I'd like to suggest, if applicable, to replace the TextArea control with the MaskInput:

    content: new /*sap.m.*/MaskInput({ // Instead of TextArea
      mask: "999999999999", // Max. 12 digits
      placeholder: "Meldungsnummer eingeben"
    }),

    This would eliminate the need to filter out all non-digit characters (liveChange handler).

    The "9" in MaskInput represents numbers by default.

    API reference: sap/m/MaskInput

    Add comment
    10|10000 characters needed characters exceeded