我有對象這樣獲取下一個項目使用數組陣營
const Guide = [
{
id: 1,
title: 'Dashboard',
content: 'The dashboard is your main homepage. It will display a feed of looks...'
},
{
id: 2,
title: 'Discover',
content: 'Discover allows you to find new looks, what is trending and search for looks, brands and users'
},
{
id: 3,
title: "Upload you look, style guide and more "
},
{
id: 4,
title: "Upload you look, style guide and more "
},
{
id: 5,
title: "Upload you look, style guide and more "
}
]
我希望能夠點擊一個按鈕,進入到顯示器的下一個對象的數據數組直到最後一個。目前,當我點擊按鈕時,它只是變成第二個對象「發現」並停在那裏,我怎樣才能確保它通過這個功能。請原諒我的語法。
這是我的狀態下,當部件安裝
componentWillMount(){
this.setState({
index: Guide[0]
})
}
初始狀態指數是= 0,這是我的函數來轉到下一個對象
moveNext =() => {
let i = Guide.indexOf(Guide[0])
if(i >= 0 && i < Guide.length)
this.setState({
index: Guide[i + 1]
})
}
謝謝你的迴應@湯姆,這種做法實際上是比我有更簡單 – Dumisani