Kotlin-JS interop - using language constructs -
i have js interop function using for in
construct iterate on input elements, it's throwing error @ runtime.
native("document") val ndoc: dynamic = noimpl fun jsinterop() { js("console.log('js inling kotlin')") val ies = ndoc.getelementsbytagname("input") (e in ies) { console.log("input element id: ${e.id}") } }
getting following js error
uncaught typeerror: r.iterator not functionkotlin.definerootpackage.kotlin.kotlin.definepackage.js.kotlin.definepackage.iterator_s8jyvl$ @ kotlin.js:2538
any suggestions on how fix one?
kotlin : m12
the generated js code function is,
jsinterop: function () { var tmp$0; console.log('js inling kotlin'); var ies = document.getelementsbytagname('input'); tmp$0 = kotlin.modules['stdlib'].kotlin.js.iterator_s8jyvl$(ies); while (tmp$0.hasnext()) { var e = tmp$0.next(); console.log('input element id: ' + e.id); } },
foreach
didn't work because it's array
function in js, getelementsbytagname
returns htmlcollection . changed kotlin code use traditional loop iterate on collection , work expected.
val ies = ndoc.getelementsbytagname("input") (i in 0..(ies.length int) - 1) { console.log("inputelement-${i} : ${ies[i].id}") }
Comments
Post a Comment