简体   繁体   English

TypeError:undefined不是一个函数(评估“ categories.map”)

[英]TypeError: undefined is not a function (evaluating 'categories.map')

Hi i have this json file like this 嗨,我有这样的json文件

[
  {
    "id": 1,
    "code":"films",
    "name":"FILMS",
    "icon":"film",
    "image":"http://static.tvmaze.com/uploads/images/large_landscape/137/343398.jpg",
    "subs": [
      {
        "id": "1-1",
        "code": "553",
        "name": "films 1",
      },
      {
        "id": "1-2",
        "code": "554",
        "name": "film 2",
      }
    ]
  },
  {
    "id": 2,
    "code":"series",
    "name":"SERIES",
    "icon":"television",
    "image":"http://static.tvmaze.com/uploads/images/large_landscape/142/356297.jpg",
    "subs": [
      {
        "id": "2-1",
        "code": "555",
        "name": "series 1",
      },
      {
        "id": "2-2",
        "code": "556",
        "name": "series 2",
      }
    ]
  }
]

I am fetching it using redux (axios) 我正在使用redux(axios)来获取它

// CATEGORIES
export function retrieveCategoriesSuccess(res) {
    return {
        type: types.RETRIEVE_MOVIES_CATEGORIES_SUCCESS,
        categories: res.data
    };
}
export function retrieveMoviesCategories() {
    return function (dispatch) {

        return axios.get(FETCHING_MOVIES_URL + "data/categories.json")
        .then(res => {
            dispatch(retrieveCategoriesSuccess(res));
        })
        .catch(error => {
            console.log("Categories: ", error); //eslint-disable-line
        });
    };
}

I try to map it to my menu this way: 我尝试通过以下方式将其映射到菜单:

    //return categories.map((obj) => (
    return this.props.categories.map((obj, key) => {
        <View key={obj.id}>
            <Text style={styles.text}>{obj.name}</Text>
        </View>
        {_renderSubMenu(obj)}
    })

when i remove the subs array the code works great and i get the menu list nbut when i add the subcategories i get this error: TypeError: TypeError: undefined is not a function (evaluating 'categories.map') 当我删除subs数组时,代码运行良好,并且我获得菜单列表nbut,但是当我添加子类别时,出现以下错误:TypeError:TypeError:undefined不是一个函数(评估'categories.map')

Console.log (this.props.categories) before the map bloc show the json data, i tried also return categories.map((obj) =>... but didn't work either Map bloc显示json数据之前的Console.log(this.props.categories),我也尝试返回category.map((obj)=> ...,但也没有用

对于任何有这样问题的人,请在您的json文件中检查逗号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在React中修复“ TypeError:category.map不是函数”错误 - How to fix “TypeError: categories.map is not a function” error in React TypeError:未定义不是函数(正在评估userItems.map) - TypeError: undefined is not a function (evaluating userItems.map) 映射函数 - 未处理的 JS 异常:TypeError:undefined 不是评估映射的对象 - Map Function - Unhandled JS Exception: TypeError: undefined is not an object evaluating map TypeError: undefined is not a function (evaluating 'this.state.list.map') - TypeError: undefined is not a function (evaluating 'this.state.list.map') TypeError:undefined不是函数(评估调度) - TypeError: undefined is not a function (evaluating dispatch) TypeError:undefined不是函数(评估&#39;$(“#typed”)。typed&#39;) - TypeError: undefined is not a function (evaluating '$(“#typed”).typed') 未处理的承诺拒绝:TypeError:未定义不是一个函数,当在react native中为setState映射时会发生&#39;departureloc.map&#39;评估 - Unhandled promise rejection: TypeError: undefined is not a function evaluating 'departureloc.map' occurs when mapping for setState in react native TypeError:'undefined'不是函数(评估'mockBackend.expectPost( - TypeError: 'undefined' is not a function (evaluating 'mockBackend.expectPost( TypeError:undefined&#39;不是函数(评估&#39;myAudio.play()&#39;)“ - TypeError: undefined' is not a function (evaluating 'myAudio.play()')" TypeError:undefined不是一个函数(评估&#39;document.getsElementsByClassName(&#39;&#39;) - TypeError: undefined is not a function (evaluating 'document.getsElementsByClassName('')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM