javascript - 如何从 jquery 对象中的变量设置键?

标签 javascript jquery

如何将“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/

相关文章:

javascript - 如果不使用返回值调用方法

javascript - 如何检查函数是否被调用?查询

javascript - .on ('hover' ) 不适用于 append 元素

javascript - 使用正则 exp 将字符串中的每个单词用 span 包裹起来

javascript - 有没有办法用 javascript 建立到 IP 的 tcp 连接?

javascript - 单击 angularjs 中的另一个元素时如何模拟单击一个元素

javascript - 如何设置选项select的值?

javascript - 我想在页面或 float 模式上添加一个 float div,使页面保持事件状态

Javascript HREF 更新

jquery - 滑动导航菜单的位置始终在标题下方