如何在某处使用此AnswerList,以便正确处理事件?我已经挣扎了太久了:/
module AnswersList (Model, Action, update, view, Answer) where
import Html exposing (..)
import Html.Events exposing (onClick)
import Html.Attributes exposing (class)
type alias Answer =
{ id : Int
, answer : String
, points : Int
, visible : Bool
}
type alias Model = List Answer
-- actions
type Action = ShowAnswer Int
update action model =
case action of
ShowAnswer aid ->
let newAnswer a = if a.id == aid then { a | visible <- True } else a
in
List.map newAnswer model
-- view
view : Signal.Address Action -> Model -> Html
view address model =
div [class "list-group"]
(List.map (viewAnswer address) model)
viewAnswer : Signal.Address Action -> Answer -> Html
viewAnswer address answer =
let answerText = if answer.visible then answer.answer else "........"
in
div [class "list-group-item", onClick address (ShowAnswer answer.id) ] [text answerText]
现在在其他模块视图中我想简单地添加一些AnswersList来查看,我不知道如何实现它:/你能帮助我吗?
我还有其他模块
model = { answers: AnswerList.model }
我希望将事件传递给AnswerList.update
以某种方式处理它们。
答案 0 :(得分:2)