I’ve been following the “Get Started” code at Svelte | Strapi Documentation but modifying it to work with my own Strapi database.
I can use all of the code in the script block and get my data returned to the console but when I try to add in the HTML code I get an error “Uncaught (in promise) Error: {#each} only iterates over array-like objects.”
Here is a sample of what my Strapi database returns to the browser console from my program…
- {data: Array(2), meta: {…}}
- data: Array(2)
1. 0:- attributes:
- Branch: “Sydney”
- Current: true
- DOB: “1981-09-01”
- DateJoined: “1991-10-11”
- Email: “david@hardsolutons.net.au”
- FirstName: “David”
- Info: null
- LastName: “Smith”
- MemberNumber: 137
- PhoneNumber: “*******”
- Postcode: ****
- Street: “*****”
- Town: “******”
- createdAt: “2021-12-16T06:06:29.877Z”
- publishedAt: “2021-12-20T07:09:45.468Z”
- updatedAt: “2022-01-02T07:04:35.508Z”
- [[Prototype]]: Object
- id: 1
This is json data as shown when accessing the strapi database directly in a browser…
{“data”:[{“id”:1,“attributes”:{“MemberNumber”:137,“FirstName”:“David”,“LastName”:“Smith”,“Street”:"“,“Town”:”",“Postcode”:***,“Email”:“david@hardsolutons.net.au”,“DOB”:“1981-09-01”,“Info”:null,“DateJoined”:“1991-10-11”,“Current”:true,“Branch”:Sydney,“createdAt”:“2021-12-16T06:06:29.877Z”,“updatedAt”:“2022-01-02T07:04:35.508Z”,“publishedAt”:“2021-12-20T07:09:45.468Z”,“PhoneNumber”:“0488542252”}}
This looks nothing like the structure of the “Example Result” shown in the “Get Started” code I am following.
How do I modify my Strapi database to give the same json structure shown in the Get Started code, or how do I modify the Svelte #each loop to extract the items from my own database?