I get this error in vlang:
a struct must have a
next() method to be an iterator
struct Items {
item []Item
}
struct Item {
name string
link string
tags []string
}
pub fn (mut app App) index() vweb.Result {
text := os.read_file(app.db) or { panic(err) }
items := json.decode(Items, text) or { panic(err) }
println(items)
return $vweb.html()
}
index.html:
@for item in items
<h2>@item.name</h2>
@end
Disclaimer, this is my second day in V lang...
I got 1 step further with this added to
stack.v
, this is just my main .v file for this scenariomaybe you understand enough to keep you going after this stone step?
it stopped complaining
a struct must have a next() method to be an iterator
and started complaining about return types and insisting on an optional.
I was able to get this far thanks to: V Docs:References V Docs: Heap Structs V Docs: Methods V lib: Method Args
I look forward to hearing if this got you anywhere, I'll keep looking at this tomorrow because I want to understand it. But I been 'grammin 13hrs straight now, and I'll do better with a clear head...