我的主要課程設(shè)置如下:class MyView : View() { val controller: PollController by inject() etc}我想傳入一個(gè)變量(如路徑文件的字符串)class PollController : Controller() {val currentData = SimpleStringProperty()val stopped = SimpleBooleanProperty(true)val scheduledService = object : ScheduledService<DataResult>() { init { period = Duration.seconds(1.0) } override fun createTask() : Task<DataResult> = FetchDataTask()}fun start() { scheduledService.restart() stopped.value = false}inner class FetchDataTask : Task<DataResult>() { override fun call() : DataResult { return DataResult(SimpleStringProperty(File(**path**).readText())) } override fun succeeded() { this@PollController.currentData.value = value.data.value // Here is the value of the test file }}}[DataResult 只是一個(gè) SimpleStringProperty 數(shù)據(jù)類(lèi)]這樣 PollController 類(lèi)中的函數(shù)可以引用路徑文件。我無(wú)法弄清楚注射是如何工作的;@Inject 始終保持紅色,添加構(gòu)造函數(shù)會(huì)拋出 Controller() 對(duì)象返回
添加回答
舉報(bào)
0/150
提交
取消