[英]How to send a data from scala to a particular div tag in Html page
I have a List[List[String]]
in my Scala side which I have to send to a div tag of a particular HTML page.我的 Scala 端有一个
List[List[String]]
,我必须将其发送到特定 HTML 页面的 div 标签。
<div class="pagecolumn" style="background-color: #FFFFFF;">
<button class="collapsible">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
.我必须将
ResultList
发送到resultDiv
。
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:如果不提供详细信息,很难准确理解为什么需要像那样处理
modelObject
或者代码中keyName
的意义是什么,但是假设您有List[List[String]]
类型的ResultList
,并且您只需要一种方法将resultList
发送到resultDiv
,这是在 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 class="pagecolumn" style="background-color: #FFFFFF;">
| <button class="collapsible">Data Info</button>
|
| <div id=$resultDiv >
|
| </div>
|</div>
|""".stripMargin
println(htmlString)
}
Outputs:输出:
<div class="pagecolumn" style="background-color: #FFFFFF;">
<button class="collapsible">Data Info</button>
<div id="This sentence is nonsense.This sentence is nonsense too" >
</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.