3

我有以下情况(试剂+ react.js):

(defn row [data]
   [:li {:key (:id data :class "myclass")} (:text data)])

(defn list [rows]
  (map #([row %]) rows))

在运行时,我可以看到 react.js 抱怨缺少 'key' 属性。有没有办法从组件函数中指定键。我希望 raw 成为一个单独的组件函数,因为它可能会变得非常大,有自己的生命周期回调等。

4

1 回答 1

3

Your code is almost correct. It should be:

(defn row [data]
  [:li {:key (:id data) :class "myclass"} (:text data)])

The end paranthesis should be after data and not "myclass".

And your mapping can be rewritten as just (map row rows) since row is already a function taking one argument.

于 2015-01-21T14:43:45.137 回答