所以,我想測試許多條件,對於不同的值...現在只是一堆if,else語句...乾淨的方式來測試不同值的許多條件?
但它看起來醜陋im確定必須有更好的方法...
有什麼想法?
林想也許有循環,但還是把所有增值經銷商在一個數組,但我找不出如何..
THX!
var dataObject = {}
if (newState.playerId){
dataObject["filter[player_id]"] = newState.playerId
}else{
dataObject["filter[player_id]"] = this.state.playerId
}
if (newState.pageLimit){
dataObject ["page[limit]"] = newState.pageLimit
}else{
dataObject["page[limit]"] = this.state.pageLimit
}
if (newState.timeFrom){
dataObject["time[from]"] = newState.timeFrom
}else{
dataObject["time[from]"] = this.state.timeFrom
}
if (newState.timeTo){
dataObject["time[to]"] = newState.timeTo
}else{
dataObject["time[to]"] = this.state.timeTo
}
if (newState.gameId){
dataObject["filter[game_id]"] = newState.gameId
}else{
dataObject["filter[game_id]"] = this.state.gameId
}
if (newState.customerId){
dataObject["filter[customer_id]"] = newState.customerId
}else{
dataObject["filter[customer_id]"] = this.state.customerId
}
if (newState.currency){
dataObject["filter[currency]"] = newState.currency
}else{
dataObject["filter[currency]"] = this.state.currency
}
if (newState.variant){
dataObject["filter[locale]"] = newState.locale
}else{
dataObject["filter[locale]"] = this.state.locale
}
if (newState.variant){
dataObject["filter[demo]"] = newState.demo
}else{
dataObject["filter[demo]"] = this.state.demo
}
在屬性上使用循環!你能告訴我們'newState'和'this.state'的定義嗎? – Bergi
基於'newState.variant'的if-else的最後兩個塊?或'locale'和'demo'狀態分別? – light
@GiorgioMartini你解決了嗎? – fcalderan