2017-03-18 7 views
0

私はこのClojure Datascriptでリストを入力して表示するにはどうすればよいですか?

(def fixtures [ 
    [:db/add 0 :system/group :all] 

    { 
    :product/name "Donut Keurig" 
    :product/category "snack" 
    :product/brand "Grocery&GourmetFood" 
    :product/height "2.1" 
    :product/width "3.2" 
    :product/notes "The Original Donut Shop Keurig Single-Serve K-Cup Pods, Regular Medium Roast Coffee" 
    } 

    { 
    :product/name "Ferrero Rocher Hazelnut Chocolates" 
    :product/category "Candy" 
    :product/brand "Candy&Chocolate" 
    :product/height "3.4" 
    :product/width "2" 
    :product/notes "A tempting combination of smooth chocolaty cream surroiunding a whole hazelnut within a delciate, crisp wafer all enveloped in milk chocolate and finely chopped hazelnuts" 
    } 
    ]) 

(def conn (d/transact! conn u/fixtures)) 

と私のデシベルいっぱいだが、私は、このエラーを示しています。

不明なエラーを:アサートに失敗しました:(CONN CONN?)Function.datascript.core.transact_BANG_.cljs $中核に$ IFN $ _invoke $アリティ私はこのようなデシベルの結果表示するだけでなく$ 3

(defmulti read om/dispatch) 

(defmethod read :product/name 
    [{:keys [state query]} _ _] 
    {:value (d/q '[:find [(pull ?e ?selector) ...] 
       :in $ ?selector 
       :where [?e :product/name]] 
      (d/db state) query)}) 

(defui product-view 
    static om/IQuery 
    (query [this] [{:product/name [:db/id :product/name]}]) 
    Object 
    (render [this] 
     (let [{:keys [product/name] :as entity} 
      (get-in (om/props this) [:product/name ""])] 
     (dom/tr nil 
      (dom/td nil name))))) 

(defui products-view 
    static om/IQuery 
    (query [this] [{:product/name [:db/id :product/name]}]) 
    Object 
    (render [this] 
     (dom/table #js {:className "table table-bordered"} 
     (dom/thead nil 
      (dom/tr #js {:className "row-garden"} 
      (dom/th nil "Product Name") 
      (dom/th nil "Category") 
      (dom/th nil "Brand") 
      (dom/th nil "Height") 
      (dom/th nil "Width") 
      (dom/th nil "Notes"))) 
     (dom/tbody 
      (let [{:keys [product/name] :as entity} 
      (get-in (om/props this) [:product/name ""])] 
      (println conn) 
      (dom/tr nil 
       (dom/td nil name))))))) 

(om/add-root! 
    reconciler 
    products-view 
    (gdom/getElement "table-products")) 

をしかし、動作しません:(

ありがとうございました!

答えて

1

ここにDataScriptの著者。

まず、取引!接続ではなくトランザクションレポートを返します。これは、引数として渡されconnの内容を変異させる:

(def conn (d/create-conn schema)) 
... 
(d/transact! conn u/fixtures) 

第二に、あなたは、クエリで動的に結合プルパターンを使用することはできません。ノーマルプルAPIを使用してください:

(let [db  (d/db state) 
     datoms (d/datoms db :aevt :product/name) 
     eids (map :e datoms)] 
    (d/pull-many db query eids)) 

私は残念なことにOm.Nextの部分でお手伝いできません。何かエラーがある場合は、わかりません。

希望します。

0

Datascript接続を正しく初期化していないようです。 DataScript example solution in this questionをご覧ください。あなたのコードはこのモデルに従うべきです:

(ns clj.core 
    (:require [tupelo.core :as t] 
      [datascript.core :as d] 
      [clojure.set :as set])) 
(t/refer-tupelo) 

(def data 
    [ {:type :x :local/id 1, :obs/A "11", :obs/value 2.0, :obs/color "yellow"} 
    {:type :x :local/id 2, :obs/A "12", :obs/value 4.0, :obs/color "blue"} 
    {:type :x :local/id 3, :obs/A "13", :obs/value 3.0, :obs/color "green"} 
    {:type :x :local/id 3, :obs/A "15", :obs/value 7.0, :obs/color "red"} 

    {:type :y :local/id 2, :obs/A "11", :obs/value 7.0, :obs/shape "square"} 
    {:type :y :local/id 2, :obs/A "13", :obs/value 4.0, :obs/shape "circle"} 
    {:type :y :local/id 6, :obs/A "15", :obs/value 3.0, :obs/shape "triangle"} ]) 

(def conn (d/create-conn {})) 
(d/transact! conn data) 
..... 
関連する問題