I have a List[List[String]] in my Scala side which I have to send to a div tag of a particular HTML page.
<div style="background-color: #FFFFFF;">
<button >Data Info</button>
<div id="resultDiv" >
</div>
</div>
def getResultantValues(modelObject: String, keyName: String):Unit = {
var result = modelObject.replaceAll("\\[","").split("]")
var resultList : mutable.MutableList[mutable.MutableList[String]]= null
for (i<-0 until result.length) {
resultList = result(i).split(",")
}}`
I have to send ResultList to the resultDiv.
CodePudding user response:
Without providing details it's quite hard to understand exactly why you need to process the modelObject like that or what is the point of keyName in your code, but assuming you have ResultList of type List[List[String]], and you just need a way to send resultList to resultDiv, here's how you can do that in Scala:
object Something extends App {
def getResultantValues(modelObject: String): String = {
val rawSentences: List[String] =
modelObject
.replaceAll("makes no sense", "is nonsense")
.split("\\.")
.toList
val resultList: List[List[String]] =
for (word <- rawSentences) yield word.strip.split(",").toList
resultList.flatten.mkString("\"", ".", "\"")
}
val resultDiv = getResultantValues(
"This sentence makes no sense. This sentence makes no sense too."
)
val htmlString =
s"""
|<div style="background-color: #FFFFFF;">
| <button >Data Info</button>
|
| <div id=$resultDiv >
|
| </div>
|</div>
|""".stripMargin
println(htmlString)
}
Outputs:
<div style="background-color: #FFFFFF;">
<button >Data Info</button>
<div id="This sentence is nonsense.This sentence is nonsense too" >
</div>
</div>
