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
Post a Comment