2017-08-27 8 views
0

両側がDom.nodeListであり、DomTokenList.forEachDom.domTokenListと予想されるため、以下は動作しません。理由不和、@anmonteiroの礼儀から言い換えbs-webapi - Dom.nodeListをループする方法は?

open Bs_webapi.Dom; 

external length : Dom.nodeList => int = "" [@@bs.get]; 

let sides = Document.querySelectorAll "#carousel > figure" document; 

DomTokenList.forEach (fun item _ => print_endline item) (sides); 
+0

あなたはもう少し我慢してしようと、このような不要なクロスポストを避ける必要があります。あなたがこれを投稿したとき、すでにDiscordに答えられました。 – glennsl

答えて

1

:ここ

Js.Array.forEach Js.log (NodeList.toArray sides); 

NodeListの各要素のための方法setAttributeの一例です。注:Element.ofNodeは、Dom.nodeoption Dom.elementに変換するために使用できます。

open Bs_webapi.Dom; 

external length : Dom.nodeList => int = "" [@@bs.get]; 

let sides = Document.querySelectorAll "#carousel > figure" document; 

Js.Array.forEachi 
    (fun side index => 
    switch (Element.ofNode side) { 
    | Some element => 
     Element.setAttribute "style" "some style here" element 
    | None =>() 
    } 
) 
    (NodeList.toArray sides) 

https://bucklescript.github.io/bucklescript/api/Js_array.html#VALforEach

関連する問題