小编Okk*_*kio的帖子

处理 elm 中的大量输入字段是否有一个很好的模式?

elm 中是否有一种模式可以避免编写大量消息只是为了更新模型子元素上的各个字段?

目前,我最终得到如下代码,每个更改的输入都有一条消息,然后是每个字段的一堆更新逻辑。我想要做的是有一个像 AChanged 这样的消息来处理对 A 的任何属性的所有更改。要么通过更新生成消息的函数中的记录,要么传入一个字段名,然后使用它来直接执行像在 Javascript 中一样更新记录。

module Main exposing (Model)

import Browser exposing (Document, UrlRequest)
import Browser.Navigation as Nav exposing (Key)
import Html exposing (div, input)
import Html.Events exposing (onInput)
import Url exposing (Url)


type alias A =
    { a : String
    , b : String
    , c : String
    , d : String
    }


type alias B =
    { e : String
    , f : String
    , g : String
    , h : String
    }


type …
Run Code Online (Sandbox Code Playgroud)

elm elm-architecture

4
推荐指数
1
解决办法
297
查看次数

标签 统计

elm ×1

elm-architecture ×1