我正在尝试这样的事情,但这个例子不起作用.
jsObj = {};
for (var i = 1; i <= 10; i++) {
jsObj{'key' + i} = 'example ' + 1;
}
Run Code Online (Sandbox Code Playgroud)
如何制作这样的动态密钥呢?
好吧,我正在努力开发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) 我正在为Jquery创建一个插件,并且需要将变量作为对象中的键.
$(selector).animate({self.settings.direction: '+='+self.displacement+'px'}, "slow" , function () {});
Run Code Online (Sandbox Code Playgroud)
这部分导致错误:
self.settings.direction
我的语法错误的任何想法?谢谢
我想发送键和值都是动态的(键是动态的,如来自用户输入).然后如何发送请求.我想要这样的东西:
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",它应该是动态的.这该怎么做?