这是你在找什么?
view : Model -> Html Msg
view model =
div []
[ fieldset []
[ radio "Small" (model.fontSize == Small) (SwitchTo Small)
, radio "Medium"(model.fontSize == Medium) (SwitchTo Medium)
, radio "Large" (model.fontSize == Large) (SwitchTo Large)
]
, Markdown.toHtml [ sizeToStyle model.fontSize ] model.content
]
radio : String -> Bool > msg -> Html msg
radio value isChecked msg =
label
[ style [("padding", "20px")]
]
[ input [ type_ "radio", name "font-size", onInput msg, checked isChecked ] []
, text value
]
Run Code Online (Sandbox Code Playgroud)
请注意,我将onClick更改为onInput,我认为这是更好的表单选择练习.
顺便说一句,我倾向于将msg参数放在类型签名的开头,因为它最不可能成为函数管道的一部分:
radio : msg -> Bool -> String -> Html msg
Run Code Online (Sandbox Code Playgroud)
这是有问题的代码:
view : Model -> Html Msg
view model =
div []
[ fieldset []
[ radio "Small" (SwitchTo Small)
, radio "Medium" (SwitchTo Medium)
, radio "Large" (SwitchTo Large)
]
, Markdown.toHtml [ sizeToStyle model.fontSize ] model.content
]
radio : String -> msg -> Html msg
radio value msg =
label
[ style [("padding", "20px")]
]
[ input [ type_ "radio", name "font-size", onClick msg ] []
, text value
]
Run Code Online (Sandbox Code Playgroud)
这是用于呈现无线电输入的行:
input [ type_ "radio", name "font-size", onClick msg ] []
Run Code Online (Sandbox Code Playgroud)
checked收音机有一个属性(请参阅文档),所以看起来您可以根据当前字体大小添加该属性?就像是:
radio : String -> Bool -> msg -> Html msg
radio value isChecked msg =
label
[ style [("padding", "20px")]
]
[ input [ type_ "radio", name "font-size", checked isChecked, onClick msg ] []
, text value
]
Run Code Online (Sandbox Code Playgroud)
...然后isChecked根据view函数中的模型设置参数。
| 归档时间: |
|
| 查看次数: |
1120 次 |
| 最近记录: |