相关疑难解决方法(0)

如何创建要添加到JavaScript对象变量的动态密钥

我正在尝试这样的事情,但这个例子不起作用.

jsObj = {};

for (var i = 1; i <= 10; i++) {
    jsObj{'key' + i} = 'example ' + 1;
}
Run Code Online (Sandbox Code Playgroud)

如何制作这样的动态密钥呢?

javascript object

196
推荐指数
1
解决办法
22万
查看次数

Javascript中对象文字的动态键

好吧,我正在努力开发Nodes中的一个项目,我遇到了一个关于对象文字中的键的小问题,我有以下设置:

var required = {
    directories : {
        this.applicationPath                    : "Application " + this.application + " does not exists",
        this.applicationPath + "/configs"       : "Application config folder does not exists",
        this.applicationPath + "/controllers"   : "Application controllers folder does not exists",
        this.applicationPath + "/public"        : "Application public folder does not exists",
        this.applicationPath + "/views"         : "Application views folder does not exists"
    },
    files : {
        this.applicationPath + "/init.js"               : "Application init.js file does not exists",
        this.applicationPath + "/controllers/index.js"  : "Application index.js controller …
Run Code Online (Sandbox Code Playgroud)

javascript object-literal

80
推荐指数
4
解决办法
3万
查看次数

javascript对象变量键

我正在为Jquery创建一个插件,并且需要将变量作为对象中的键.

$(selector).animate({self.settings.direction: '+='+self.displacement+'px'}, "slow" , function () {});
Run Code Online (Sandbox Code Playgroud)

这部分导致错误:

self.settings.direction

我的语法错误的任何想法?谢谢

javascript jquery

28
推荐指数
3
解决办法
3万
查看次数

如何在jQuery Ajax中发送动态密钥和值?

我想发送键和值都是动态的(键是动态的,如来自用户输入).然后如何发送请求.我想要这样的东西:

var requestString;

if(something)
   requestString = "something";
else
   requestString= "else";

    jQuery.ajax({
                        url: handlerUrl,
                        dataType: "json",
                        data: {
                            requestString: request.term
                        }
                    });
Run Code Online (Sandbox Code Playgroud)

这里requestString是一个变量并动态设置.但对于当前的代码.关键是它本身变成了"requestString",它应该是动态的.这该怎么做?

javascript ajax jquery dynamic

5
推荐指数
1
解决办法
3013
查看次数

标签 统计

javascript ×4

jquery ×2

ajax ×1

dynamic ×1

object ×1

object-literal ×1