2017-12-27 1905 views
-1

我想在我的地圖內運行一個函數......但地圖只運行函數而不是代碼的其餘部分。試圖在MAP中運行函數

編輯:我意識到我沒有真正解釋這種情況。我正在嘗試運行this.math,以便爲每個呼叫獲取新的唯一值。

math =() => { 
 
    var add = this.state.add + 1 
 
this.setState({ 
 
    add: add 
 
}) 
 
console.log(add) 
 
} 
 

 
var projects = this.state.key.map((key) => { 
 
    this.math() 
 
    ` &filter[where][or][${this.state.add}][id]=${key.fk}` 
 
})

+1

你可能希望你的函數實際返回一些東西。 – SLaks

+0

'this.math()'做了什麼或者返回了什麼,你期望模板文字做什麼? 'map()'也期望返回。不清楚你的期望是在這裏 – charlietfl

+1

我不知道'this.math()'做了什麼,但它完全與它後面的字符串無關。 – dzny

回答

0

我想通了!非常感謝你的洞察力。這也是我在堆棧溢出中的第一篇文章。下面你會發現我的修復,我希望這可以幫助其他人在未來。

 var projects = this.state.key.map((key) => {this.math() 
    return (`&filter[where][or][${this.state.add}][id]=${key.fk}`); 
})