[
{
"title": "大写汉字数字",
"content": "零,壹,贰,叁,肆,伍,陆,柒,捌,玖,拾,佰,仟"
},
{
"title": "大写英文数字",
"content": "one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirtheen,fourtheen,fifteen,sixteen"
}
]
button("加载文件") {
action {
_chooseFile()
}
}
private fun _chooseFile() {
val fileType = listOf("*.json", "*.txt")
val efset = arrayOf(FileChooser.ExtensionFilter("$fileType", fileType))
val fileschoosed = chooseFile("选择文件", efset, mode = FileChooserMode.Single) {
// p初始目录为当前项目目录
initialDirectory = File(File("").canonicalPath)
}
if (fileschoosed.isNotEmpty()) {
_init(fileschoosed.first().toURI().toURL())
}
}
//存放 "title"和 "content"的map
private val typeMap = observableMapOf<String, String>()
private fun _init(filePath:URL){
types.clear()
typeMap.clear()
types.add("数字")//不论加载什么内容,将"数字"和"自定义"保留为默认项
loadJsonArray(filePath).map {
val obj = it.asJsonObject()
types.add(obj.getString("title"))//每次添加一项,能保证types中的顺序与json文件中的一致
typeMap.put(obj.getString("title"), obj.getString("content"))
}
// types.addAll(typeMap.keys)//此种方式会打乱顺序
types.add("自定义")
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有