Can I pass a multiline string to js()?
# kvision
j
Can I pass a multiline string to js()?
Currently I have
Copy code
private fun toolTipCallback(): TooltipCallback {
    return TooltipCallback(
        footer = js(
            "function(context) {"
                    + "var ctx = context[0];"
                    + "var chart = ctx.chart;"
                    + "var ccc = chart.config._config;"
                    + "var data = ccc.data;"
                    + "var i = ctx.dataIndex;"
                    + "return data.labels[i];"
                    + "}"
        )
    )
}
Which is a bit ugly.
I think I've tried already with val str =""" [...] """
Which didn't work.
... const val in an companion object works.
t
Tripple quote works:
Copy code
js("""
your code...

""")
But be aware the string must be literal, because it is processed during compilation not in runtime e.g
Copy code
js("""
your code...
""".trimIndent())
or
Copy code
js("""
    $somevariable
""")
will not work
j
Thanks Tomas, I've come to a similar solution by now:
Copy code
fun tooltipCallbackFooterJsFunction(): dynamic {
    return js(
        """function(context) {
                    var ctx = context[0];
                    var chart = ctx.chart;
                    var ccc = chart.config._config;
                    var data = ccc.data;
                    var i = ctx.dataIndex;
                    return data.labels[i];
        }"""
    )
}
within companion object.