SQL极简教程 · MySQL · MyBatis · JPA 技术笔记 教程 总结禅与计算机程序设计艺术技术雷达

想使用 Kotlin DSL for HTML 来这样写前端的代

2018-09-03  本文已影响23人  光剑书架上的书
    private fun renderBooks(data: Array<String>) {
        val books = document.create.div("books") {
            table("table table-hover") {
                thead {
                    tr {
                        th {
                            +"ID"
                        }
                        th {
                            +"Name"
                        }
                    }
                }
                tbody {
                    data.forEachIndexed { index, s ->
                        tr {
                            td {
                                +"$index"
                            }
                            td {
                                +s
                            }
                        }
                    }
                }
            }
        }
        document.getElementById("books")?.appendChild(books)
    }

完整实例代码参考:https://github.com/Jason-Chen-2017/kotlin-js-gradle-demo

kotlinx.html参考文档:https://github.com/Kotlin/kotlinx.html

上一篇 下一篇

猜你喜欢

热点阅读