Javascript 如何从jquery对象中的变量设置键?
如何将“nom_article”键更改为s值Javascript 如何从jquery对象中的变量设置键?,javascript,jquery,Javascript,Jquery,如何将“nom_article”键更改为s值 var s = document.getElementById("myvalue").textContent; var obj = { url: "http://localhost:53698/mobile_ODataService.svc/", jsonp: true, errorHandler: function (error) {
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" };
您必须在对象创建后执行此操作
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" },
};
可能重复的