小编Cod*_*Man的帖子

使用 HTMX 更换整个身体

我有以下内容index.html

<head>
<meta charset="UTF-8">
<script src="https://unpkg.com/htmx.org@1.9.5"></script>
</head>
<body id="bomb-main" class="main-page">
<div class="bomb"
     hx-trigger="click"
     hx-swap="outerHTML"
     hx-target="#bomb-main"
     hx-get="/boom"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

/boom返回以下响应

<body id="bomb-main" class="bomb-animation">
<h1>ka-boom</h1>
</body>
Run Code Online (Sandbox Code Playgroud)

单击 时,主体将被替换,但类保持不变。

<body id="bomb-main" class="main-page">
<h1>ka-boom</h1>
</body>
Run Code Online (Sandbox Code Playgroud)

如何更改 的类body

html javascript htmx

5
推荐指数
1
解决办法
1422
查看次数

特征定义名称后面的大括号在 scala 中意味着什么?

在使用时Future我看到人们使用

Future{
      Thread sleep 500
      promise success "You've just completed the promise with me in it!"
 }
Run Code Online (Sandbox Code Playgroud)

看看 的定义Future,我可以看出 Future 是一个特质

但是当我制作自己的特质时,示例:

trait t{}
def main(args: Array[String]): Unit = {
    t{
        println("Test")
    }
}
Run Code Online (Sandbox Code Playgroud)

它无法编译。为什么?

scala

0
推荐指数
1
解决办法
70
查看次数

使用特征中定义的 unapply

我有一个特质

trait A {
    def doSomething(a: Seq[Int]): Seq[String] = {
        a.map {
            case AA(s) => s // want to use unapply defined in trait (this(AA) not allowed)
            case _ => "idc"
        }
    }
    
    def unapply(a: Int): Option[String] = getString(a)

    
    def getString(a: Int): Option[String] = {
        a match {
            case 1 => Some("one")
            case 2 => Some("two")
            case _ => None
        }
    }
}

object AA extends A
object AA2 extends A {
    override def getString(a: Int): Option[String] = {
        super.getString(a).orElse{ …
Run Code Online (Sandbox Code Playgroud)

scala pattern-matching unapply

0
推荐指数
1
解决办法
167
查看次数

标签 统计

scala ×2

html ×1

htmx ×1

javascript ×1

pattern-matching ×1

unapply ×1