Reputation: 444
How to change the "nom_articole" key to the s value?
var s = document.getElementById("myvalue").textContent;
var obj = {
url: "http://localhost:53698/mobile_ODataService.svc/",
jsonp: true,
errorHandler: function (error) {
alert(error.message);
},
entities: {
nom_articole/*I want here the s value in nom_articole place*/: { key: "id" },
}
};
Upvotes: 0
Views: 932
Reputation: 1884
You have to do this after the object creation.
var s = document.getElementById("myvalue").textContent;
var obj = {
url: "http://localhost:53698/mobile_ODataService.svc/",
jsonp: true,
errorHandler: function (error) {
alert(error.message);
}
};
obj[s] = {
nom_articole: { key: "id" },
};
Upvotes: 0
Reputation: 74046
You can't use a variable as identifier in an object literal. You just can add another dynamic property after object creation:
var s = document.getElementById("myvalue").textContent;
var obj = {
url: "http://localhost:53698/mobile_ODataService.svc/",
jsonp: true,
errorHandler: function (error) {
alert(error.message);
},
entities : {}
};
obj.entities[s] = { key: "id" };
Upvotes: 2