有条件地更改更新中的记录
我希望对 Msg
进行一些逻辑处理,并根据结果以不同的方式更新
视图。
我正在翻转一些卡片,并且我想测试其中的两张。然后,将它们作为一对接受或丢弃并重试。
update : Msg -> Model -> Model
update msg model =
case msg of
ClickedCard data ->
{ model
| activeCard = data.id
, (if List.lenght selectedCards < 2 then
selectedCards = data.id :: model.selectedCards
else if (List.take 1 model.selectedCards) == (List.drop 1 model.selectedCards) then
completedPairs = ( List.take 1 model.selectedCards , List.drop 1 model.selectedCards ):: model.completedPairs
else
selectedCards = List.drop 2 model.selectedCards)
}
_ ->
model
但是,似乎我无法在那里插入逻辑。我应该把它放在哪里?
-- PROBLEM IN RECORD ------------------------------------------ src/Flipping.elm
I am partway through parsing a record, but I got stuck here:
126| { model
127| | activeCard = data.id
128| , (if List.lenght selectedCards < 2 then
^
I was expecting to see another record field defined next, so I am looking for a
name like userName or plantHeight.
I would like to have some logic worked upon the Msg
and, depending on the result, update
the view in a different ways.
I'm flipping some cards, and I want to test two of the selected ones. Then, accept them as a pair or discard and try again.
update : Msg -> Model -> Model
update msg model =
case msg of
ClickedCard data ->
{ model
| activeCard = data.id
, (if List.lenght selectedCards < 2 then
selectedCards = data.id :: model.selectedCards
else if (List.take 1 model.selectedCards) == (List.drop 1 model.selectedCards) then
completedPairs = ( List.take 1 model.selectedCards , List.drop 1 model.selectedCards ):: model.completedPairs
else
selectedCards = List.drop 2 model.selectedCards)
}
_ ->
model
But, seems like I can't insert the logic there. Where should I put it, instead?
-- PROBLEM IN RECORD ------------------------------------------ src/Flipping.elm
I am partway through parsing a record, but I got stuck here:
126| { model
127| | activeCard = data.id
128| , (if List.lenght selectedCards < 2 then
^
I was expecting to see another record field defined next, so I am looking for a
name like userName or plantHeight.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
记录更新语法不是这样工作的。
您可以执行以下操作。
The record update syntax doesn't work like that.
You can do the following.