首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基本渲染道具转换为Reagent

基本渲染道具转换为Reagent
EN

Stack Overflow用户
提问于 2019-11-05 11:19:33
回答 1查看 400关注 0票数 0

所以我试着用试剂渲染MUi自动完成。这是我的尝试

代码语言:javascript
复制
(def options
  (clj->js
     [{:title "title" :year 1990}
      {:title "title2" :year 2990}]))

    (defn autocomplete-text-field []
      [:> TextField
        {:label "Headers"
                 :id "header"
                 :variant "outlined"
                 :fullWidth true }
       ]
   )

(defn add-header-form []
  [:> Card
   {:style #js {:max-width 1000}}
   [:> CardHeader {:title "Add Header"}]
   [:> CardContent
    [:> Grid
     {:container true
      :direction "column"}
     [:> Autocomplete
      {
       :renderInput (r/reactify-component autocomplete-text-field)
       :options options
       :getOptionLabel #(get % :year)}

      ]
     ]
    ]]
  )

我试着直接传递它,意思是:renderInput autocomplete-text-field,但无法理解。我正在尝试翻译梅页面中的示例:

https://material-ui.com/components/autocomplete/

编辑

代码语言:javascript
复制
<Autocomplete
  options={top100Films}
  getOptionLabel={(option: FilmOptionType) => option.title}
  style={{ width: 300 }}
  renderInput={params => (
    <TextField {...params} label="Combo box" variant="outlined" fullWidth />
  )}
/>

那么,我想要做的是,如何为renderInput属性编写相应的试剂代码呢?

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-05 19:02:23

renderInput需要一个返回React元素的函数。

您可以在reagent中通过

代码语言:javascript
复制
:renderInput (fn [params] (r/as-element [autocomplete-text-field params]))

params很可能是一个JS对象,这意味着您可能需要一些JS互操作来将任何支持应用到textfield。不知道它会通过什么样的params

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58710273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档