如果使用elm-lang,则管道`|`运算符会做什么?

问题描述 投票:2回答:2

我的榆木代码中有以下这段代码。


type alias Model =
  { content : String
  }


update : Msg -> Model -> Model
update msg model =
  case msg of
    Change newContent ->
      { model | content = newContent }

{ model | content = newContent }做什么?它是否将newContent的值分配(绑定)到model以及content,这就是为什么|运算符放在那里的原因?

elm
2个回答
7
投票

管道不是case表达式的一部分。它是记录更新语法,如此处所述:https://elm-lang.org/docs/records#updating-records

{ model | content = newContent }

newContent的值分配给content记录中的model字段。


0
投票

阅读|为“ with”。

{模型'with'内容(设置为= newContent}

© www.soinside.com 2019 - 2024. All rights reserved.