5

在 clojurescrtipt 中编写 reactjs 教程期间,我发现this-as宏编译为

(function(){var t = this; return t;}

它总是指向反应类中的窗口。有时我可以通过js* this但不是在内部letmap因为它们也被编译为函数来解决这个问题。

我如何thislet表单中访问 react js?

小提琴情况:http: //jsfiddle.net/VkebS/57/

和一块教程仅供参考:

(def comment-list 
  (React/createClass 
   #js{:render 
       (fn [] (dom/div #js {:className "commentList"}
                       (let [d (this-as t (.. t -props -data))]
                         (map #(commnt #js {:author (:author %)} (:text %)) d))))}))

PS:我可以使用本机数组来存储数据和本机地图功能

(def comment-list 
  (React/createClass 
   #js{:render 
       (fn [] (dom/div #js {:className "commentList"}
                       (.map (.. (js* "this") -props -data) #(commnt #js {:author (:author %)} (:text %)))))}))

这行得通,但是...

4

1 回答 1

4

this-as如果您在render功能开始时使用它,则可以使用:

(def commnt
  (React/createClass
   #js {:render
        (fn []
          (this-as this
                   (dom/div #js {:className "comment"}
                            (dom/h2 #js {:className "commentAuthor"}
                                    (.. this -props -author))
                            (dom/span #js {:dangerouslySetInnerHTML
                                           #js{:__html
                                               (.makeHtml converter (..  (js* "this") -props -children toString))}}))))}))

另见:https ://github.com/swannodette/om/blob/master/src/om/dom.cljs#L34

于 2013-12-16T16:11:12.970 回答