在 clojurescrtipt 中编写 reactjs 教程期间,我发现this-as
宏编译为
(function(){var t = this; return t;}
它总是指向反应类中的窗口。有时我可以通过js* this
但不是在内部let
或map
因为它们也被编译为函数来解决这个问题。
我如何this
在let
表单中访问 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 %)))))}))
这行得通,但是...