-1

我制作的应用程序是一个电影网站,根据您的搜索显示电影。您也可以添加收藏夹,但它不会链接到您的个人资料。所以我想出的解决方案是在 redux 的配​​置文件初始状态中设置另一个值。

export const profileInitialState = [
{pass: '123', user: 'daniel', email: 'daniel@123.com', favourites: 'batman' },
]

interface IProfileState {
    pass: string, 
    user: string,
    email: string,
    favourites?: string
}

然后从那里映射它

{data.profileReducer.slice(data.profileReducer.indexOf( {user: currUser, pass: password, email: email}, 1)).map(info =>
  <p key={data.profileReducer.length + 1.5} > {info.favourites} </p>)}

甚至认为它在控制台中完美运行,当我在代码中实现它时,它告诉我 profileReducer.indexOf 不是一个函数。

4

1 回答 1

0

First of all, Array.prototype.indexOf() can't be used to find the index of object elements in the array.

How to get index of object by its property in JavaScript?. This link describes how you can get the index of array elements.

The error can be caused by a few reasons

  • data.profileReduceris undefinded or null
  • data.profileReducer is not an array
于 2020-01-16T09:35:42.797 回答