應該是一個簡單的答案,可能是我的語法不正確,因爲我是ReactJS的新手。我想分配一個唯一的ID作爲關鍵。Javascript設置uniqueId()作爲數組鍵值
這將引發一個錯誤:
rows:{
uniqueId() : { name:"Kitchen Remodel", value:20100 },
uniqueId() : { name:"Basement Remodel", value:8300 }
}
這不?請解釋...
rows:{
143434 : { name:"Kitchen Remodel", value:20100 },
984578 : { name:"Basement Remodel", value:8300 }
}
謝謝!
對象的_The陣列一個東西_?您可以使用'[uniqueId()]'使您的示例在新的和現代的JS中工作,以便對鍵的名稱進行評估,但我並不真正瞭解您的目標是什麼。 –
這個問題似乎沒有什麼特定的ReactJS,它似乎已經有一些答案在這裏:http://stackoverflow.com/questions/2274242/using-a-variable-for-a-key-in- a-javascript-object-literal –
糖果感謝,這個問題似乎是關鍵。 – Paul