如何将“nom_articole”键更改为s值?
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" },
}
};
最佳答案
您不能在对象文字中使用变量作为标识符。您只需在创建对象后添加另一个动态属性即可:
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" };
关于javascript - 如何从 jquery 对象中的变量设置键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18658191/