我想打开一个对话框,并在对话框返回ok后处理数据。问题是:提交对话框后不会调用success-fn。这与按钮中的监听器有关。如果在没有侦听器的情况下调用connectDialog,则调用函数:success-fn。
码:
(def dbConnectionForm
(grid-panel :columns 2
:items ["Database Driver" (combobox :id :dbdriver :model ["postgresql" "mysql"])
"Database" (text :id :dbname :text "postgres")
"Port" (text :id :dbport :text "32768")
"Username" (text :id :username :text "postgres")
"Password" (text :id :password :text "postgres")]))
(defn connectionDialog []
(print (-> (dialog
:content dbConnectionForm
:option-type :ok-cancel
:type :plain
:success-fn (fn [e] (print (value dbConnectionForm)))
)pack! show!))
)
(def connectButton (button :text "Connect"
:listen [:action (fn [e] (connectionDialog))]))
这可能是因为你正在使用print
。将其更改为println
或在flush
之后在回调中添加对print
的调用。
如果(value dbConnectionForm)
返回一个较小的值(如转换为String只有几个字符的东西),并且不包含换行符,则可能不会提示outstream自动刷新,因此文本卡在缓冲区中。