build javascript array from another function -


i have translation function call : _("my text").

i trying build array :

    var data = {                         _("region"):[                             {"id": "vignoble","name": _("vineyard") },                             {"id": "sousvignoble","name": _("sub vineyard") },                             {"id": "soussousvignoble","name": _("sub sub vineyard") },                             {"id": "appellation","name": _("appellation") },                             {"id": "denomination","name": _("denomination") }                         ]}; 

it works great translating property "name" : _("my text") throws "syntax error : missing : after property id" first level _("region").

i've tried replace : 1. function(){_("region")} 2. define variable , replace _("region") variable name of variable prints , not value

any idea appreciated !

you cannot use dynamic property names in object literals. can assign property after object created, using bracket notation:

var data = {}; data[_("region")] = [...]; 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -