标签: kotlinx-html

当使用 kotlinx.html 的 DSL 创建 HTML 时,(如何)可以引用创建的元素?

我正在用 Kotlin/JS 编写一个浏览器应用程序,并使用kotlinx.htmlDSL 来生成一些 HTML。对于(一个简单的)例子:

\n
(window.document.body!! as Node).append {\n    p {\n        +"Some text"\n    }\n    p {\n        +"Click here"\n        onClickFunction = { event ->\n            <Do some stuff here...>\n        }\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

现在我的问题是我希望能够引用此代码创建的元素。例如,假设当用户单击第二个p元素(其中有一个单击事件处理程序)时,我想对第一个元素执行某些操作p(例如更改其文本)。有没有一种优雅的方法来做到这一点?

\n

我知道我可以以某种方式找到该元素(例如,通过给它一个 ID,然后查找它,或者依靠它的位置或其他东西),并且我可以在事件处理程序中执行此操作,或者如果我愿意,可以在某些中执行此操作其他代码将在创建元素后运行 \xe2\x80\x93 但仍作为初始化 \xe2\x80\x93 的一部分,并将在事件处理程序随后可以使用的某个变量中保存对该元素的引用。但是,当我的代码在那里定义该元素时,做类似的事情感觉像是一种解决方法,因此我正在寻找一种方法来获取对该元素的引用,作为构建它的过程的一部分(如果可能的话)。

\n

kotlinx-html kotlin-js

4
推荐指数
1
解决办法
892
查看次数

Could not find org.jetbrains.kotlinx:kotlinx-html:0.6.4

I'm trying to test the HTML Application, my build.gradle dependencies are:

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    compile "org.jetbrains.ktor:ktor-core:$ktor_version"
    compile 'org.jetbrains.kotlinx:kotlinx-html:0.6.4'
    compile "org.jetbrains.ktor:ktor-netty:$ktor_version"
    compile "org.apache.commons:commons-email:1.4"
    compile "org.slf4j:slf4j-simple:1.7.25"
    compile "ch.qos.logback:logback-classic:1.2.1"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}
Run Code Online (Sandbox Code Playgroud)

I got the below error while running gradle build:

Could not find org.jetbrains.kotlinx:kotlinx-html:0.6.4

what is the error here?

gradle kotlin ktor kotlinx-html

3
推荐指数
1
解决办法
3317
查看次数

Kotlin HTML-Builder

Kotlin 页面中HTML-Builder我可以看到下面的代码,如何在简单的 .tk 文件中使用它?如何开始?

val data = mapOf(1 to "one", 2 to "two")

createHTML().table {
    for ((num, string) in data) {
Iterate over data
        tr {
Functions to create HTML tags
           td { +"$num" } 
           td { +string }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

kotlin kotlinx-html kotlin-html-builder

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

使用 kotlinx.html DSL 创建 CSS 类

我正在使用Kotlin 到 Javascript插件和kotlinx.html库来构建示例应用程序:

fun main(args: Array<String>) {
    window.onload = {
        document.body!!.append.div {
            a("#", classes = "red") {
                +"Link"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想a将带有“红色”CSS 类的链接绘制为红色。
现在我使用unsage+raw来做到这一点:

document.head!!.append.style {
    unsafe {
        raw(".red { background: #f00; }")
    }
}
Run Code Online (Sandbox Code Playgroud)

如何使用 kotlinx.html DSL 创建 CSS 类?我没有找到任何与 css DSL 相关的文档。

javascript css dsl kotlin kotlinx-html

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