2016-07-21 3 views
0

javascriptで動的jsonオブジェクトを追加しました。コードは次のようになります。文字列キーを使用した動的jsonオブジェクト

if (!beadz[color.title]) 
    beadz.push({ 
    (color.title): { 
     bead.title: { 
      "inventoryQuantity": bead.inventory_quantity, 
      "currentQuantity": 1 
     } 
    } 
}); 

ただし、コードが機能していないため、構文エラーが発生しています。私は何が足りないのですか?親切にお手伝いください。

+0

あなたはなぜあなたは*何*構文エラー、あなたが得る私たちに教えていない – htoniv

+0

を使用しているJSONを提供してください? – str

+0

'(color.title):'は無効な構文です。あなたは '[color.title]:'を意味しましたか? –

答えて

1

あなたはES6

を使用している場合
if(!beadz[color.title]) 

       beadz.push({[color.title]:{[bead.title]:{"inventoryQuantity":bead.inventory_quantity,"currentQuantity":1}}}); 
+0

ここに構文エラーがあります。いいえ閉じる ']' –

+0

申し訳ありません –

関連する問題