question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: data.forEach is not a function at Store.fetchListSuccess

See original GitHub issue

I try fetchList from wordpress API custom navigation, but vuex crud return this error:

TypeError: data.forEach is not a function at Store.fetchListSuccess

What am I doing wrong? My JSON structure look like this: [ { "id": 2959, "name": "1_Websites", "slug": "1_websites", "description": "", "count": 4, "items": [ { "id": 46783, "order": 1, "parent": 0, "title": "Blog", "url": "https://google.com", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 46783, "object": "custom", "type": "custom", "type_label": "Custom Link", "object_slug": "blog" }, { "id": 46779, "order": 2, "parent": 0, "title": "Kontakt", "url": "https://google.com/", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 46779, "object": "custom", "type": "custom", "type_label": "Custom Link", "object_slug": "kontakt" }, { "id": 46781, "order": 3, "parent": 0, "title": "Home", "url": "https://google.com/", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 46781, "object": "custom", "type": "custom", "type_label": "Custom Link", "object_slug": "home" }, { "id": 46782, "order": 4, "parent": 0, "title": "Ideas", "url": "https://google.com", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 46782, "object": "custom", "type": "custom", "type_label": "Custom Link", "object_slug": "ideas" } ], "meta": { "links": { "collection": "https://google.com/", "self": "https://google.com" } } }, { "id": 2957, "name": "2_Office", "slug": "2_office", "description": "", "count": 4, "items": [ { "id": 46771, "order": 1, "parent": 0, "title": "Word", "url": "https://office.live.com/start/Word.aspx", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 46771, "object": "custom", "type": "custom", "type_label": "Custom Link", "object_slug": "word" }, { "id": 46772, "order": 2, "parent": 0, "title": "Excel", "url": "https://office.live.com/start/Excel.aspx", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 46772, "object": "custom", "type": "custom", "type_label": "Custom Link", "object_slug": "excel" }, { "id": 46773, "order": 3, "parent": 0, "title": "PowerPoint", "url": "https://office.live.com/start/PowerPoint.aspx", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 46773, "object": "custom", "type": "custom", "type_label": "Custom Link", "object_slug": "powerpoint" }, { "id": 46774, "order": 4, "parent": 0, "title": "OneNote", "url": "https://www.onenote.com/notebooks", "attr": "", "target": "", "classes": "", "xfn": "", "description": "", "object_id": 46774, "object": "custom", "type": "custom", "type_label": "Custom Link", "object_slug": "onenote" } ], "meta": { "links": { "collection": "https://google.com", "self": "https://google.com" } } } ]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
JiriCharacommented, Sep 12, 2017

Hey, glad to you have found it out 🎉. You can use parseList option in your crud module to transfer your response to array:

import createCRUDModule from 'vuex-crud'

const crudModule = createCRUDModule({
  resource: 'menus',

  idAttribute: 'ID', // use ID as an attribute

  parseList(res) {
    const data = res.data;

    return Object.assign({}, res, {
      data: data.data // retrieve array from the json response
    });
  }
})

const state = () => crudModule.state

const { actions, mutations, getters } = crudModule

export {
  state,
  actions,
  mutations,
  getters
}
0reactions
kajculacommented, Sep 12, 2017

I found where was a problem. It was a problem not with vuex-crud but with Wordpress Rest API. JSON was Object with Objects but should be Array of Objects. Second thing is that Wordpress always return id key name like “ID” not “id”. Thank you for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: data.forEach is not a function - Stack Overflow
I believe data is a JSON string. Since forEach() is a array function and you are trying to implement it on the JSON...
Read more >
TypeError: forEach is not a function in JavaScript | bobbyhadz
The "TypeError: forEach is not a function" error occurs when we call the forEach() method on a value that is not of type...
Read more >
HTML : TypeError: data.forEach is not a function - YouTube
HTML : TypeError : data. forEach is not a function [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] HTML : TypeError :...
Read more >
TypeError: foreach is not a function in JavaScript - Java2Blog
TypeError : .foreach is not a function occurs when we call foreach() function on object which is not array, Set or Map. To...
Read more >
4.2 "TypeError: arrayName.forEach is not a function"
I passed the exercise with the following, without forEach: String.prototype.rotate = function(n) { // n is an integer n %= this.length; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found