【问题标题】:Clojure / seeseaw.core/table lazy-seq retrieval failureClojure/seeseaw.core/tablelazy-seq 检索失败
【发布时间】:2017-12-19 16:17:03
【问题描述】:

我的“(list-projects)”方法从 SQLITE 数据库中查询出地图。

    (doall (apply prn (pm.models.db/list-projects)))    

pm.core==>{:id 1, :name "MyTestProj", :owner "mbc", :date "2017-12-19 13:12:45"} {:id 2, :name "newproject1", :owner "mbc", :date "2017-12-19 13:12:45"} {:id 3, :name "newproject1", :owner "mbc", :date "2017-12-19 13:12:45"} {:id 4, :name "abc", :owner "def", :date "2017-12-19 13:12:45"} {:id 5, :name "abc", :owner "def", :date "2017-12-19 13:12:45"} {:id 6, :name "abc", :owner "def", :date "2017-12-19 13:12:45"} {:id 7, :name "newproject1", :owner "mbc", :date "2017-12-19 13:12:45"} {:id 8, :name "", :owner "", :date strong text"2017-12-19 13:12:45"}

我想在构建 seesaw.core/frame/mig-panel/table (JFrame/JPanel/JTable) 时使用 :row 属性填充这些结果。

(def main-panel 
  (mig-panel
  :constraints ["fill, ins 0"]
  :items [[(seesaw.core/table
                  :id :tbl1
                  :size [640 :by 480]
                  :model [:columns [:id :name :owner :date]
                          :rows [(doall (apply prn (pm.models.db/list-projects)))]
                         ]) "grow"]
         ]))

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling form-init4108264894568019320.clj at (44:16)
   ang.Thread/run

1. Caused by java.lang.IllegalArgumentException
   row must be a map or vector, got null

如果我插入地图 {:id 1, :name "MyTestProj", :owner "mbc", :date "2017-12-19 13:12:45"} {:id....... .}{}{}{}{} 直接,它工作正常,表中的行已正确填充,因此 (doall (apply prn (pm.models.db/list-projects))) 的输出格式是我需要的。

如何在 seesaw.core/mig-panel 的上下文中检索(我认为)lazy-seq? 谢谢 莫蒂默

【问题讨论】:

  • 你不需要doall。面板需要实现列表才能使用它(虽然不是这里的问题)。
  • 如果您希望 (apply prn 评估为行列表,您可能不应该将 :rows 包装在向量中。我不希望这会导致该错误,但如果让我觉得是错误的。如果应该只是:rows (apply prn (pm.models.db/list-projects))
  • 感谢您的提示。解决方法是:rows (pm.models.db/list-projects) mig-panel需要vector或者map,我可以直接使用查询出来的vector。

标签: clojure jtable lazy-sequences seesaw


【解决方案1】:
pm.core> (pm.models.db/list-projects)
({:id 1, :name "MyTestProj", :owner "mbc", :date "2017-12-19 13:12:45"} {:id 2, :name "newproject1", :owner "mbc", :date "2017-12-19 13:12:45"} {:id 3, :name "newproject1", :owner "mbc", :date "2017-12-19 13:12:45"} {:id 4, :name "abc", :owner "def", :date "2017-12-19 13:12:45"} {:id 5, :name "abc", :owner "def", :date "2017-12-19 13:12:45"} )
pm.core> 

(pm.models.db/list-projects) 生成一个可以直接用作 :rows 键值的列表(无括号)。 :rows (pm.models.db/list-projects)

感谢 Carcigenicate 的建议。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-01
    • 2016-09-21
    • 2015-05-20
    • 1970-01-01
    • 2015-10-28
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多