gpt4 book ai didi

purescript - 我如何才能将 Maybe 转换为 Value?

转载 作者:行者123 更新时间:2023-12-05 07:24:30 25 4
gpt4 key购买 nike

我的代码有问题 我正在尝试编译它,但它抛出无法匹配 Maybe ElementElement

为什么? Maybe 如何工作?如何将其转换为值?为什么 monads 和 functor 这么难理解,为什么没有一个简单的库可以让一些新手开始使用纯脚本?:P

(对于那些不明白的人我只问了前3个)

module Main where

import Prelude --(Unit, bind, pure, ($), (<$>))
import Effect (Effect)
import Data.Maybe --(Just,Maybe,fromJust, fromMaybe)
import Data.Foldable (traverse_)
import Effect.Console (log)

import Web.HTML (window)
import Web.HTML.Window (document)
import Web.HTML.HTMLDocument (toNonElementParentNode)
import Web.Event.Event (Event, target)
import Web.HTML.HTMLInputElement (value, fromEventTarget)

import Web.DOM.NonElementParentNode (NonElementParentNode,getElementById)
import Web.DOM.Node (setTextContent)
import Web.DOM.Element (Element,toNode)
import Web.Event.EventTarget (addEventListener)

pname = "#inputName" :: String
bname = "#badgeName" :: String

main :: Effect Unit
main = do
nod1 <- returnNonElementParentNode
--querySelector :: QuerySelector -> ParentNode -> Effect (Maybe Element)
elementTarget <- getElementById pname nod1
--addEventListener :: EventType -> EventListener -> Boolean -> EventTarget
addEventListener "input" updateBadge false elementTarget

updateBadge :: Event -> Unit
updateBadge event = do
nod2 <- returnNonElementParentNode
elementTarget <- getElementById bname nod2

tget <- target event
inml <- fromEventTarget tget
input <- value inml

badge <- toNode (pure elementTarget)

if not(badge == Nothing)
then setTextContent input (toNode badge)
else Nothing

returnNonElementParentNode :: Effect NonElementParentNode
returnNonElementParentNode = do
win <- window
doc <- document win
--let nd = toNonElementParentNode doc
let
nod = toNonElementParentNode doc
pure nod

我只想了解如何从 htmlInputElement 获取输入值并将其传递给另一个 HTMLElement 的 textContent

关于如何将 Maybe 转换为 Value 以传递给 toNode 函数

最佳答案

关于purescript - 我如何才能将 Maybe 转换为 Value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55410173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com