[英]Nested object using square bracket notation in javascript
I want to use square bracket notation instead of literal in order use PHP with my name pairs. 我想使用方括号表示法代替文字,以便将PHP与我的名称对一起使用。
Here as literal notation: 这里是文字符号:
$selector.plugin({
item: 'something',
item2: true,
item3: {
option1: 60,
option2: 10
}
});
Here is what I have for square bracket notation: 这是方括号符号的含义:
var items = {};
var options = {};
items['item'] = '.item';
items['item2'] = true;
items['item3'] = options;
options['option1'] = 60;
options['option2'] = 10;
$selector.plugin(items);
What am I doing wrong here? 我在这里做错了什么? Again how do you nest objects in another using square bracket notation? 同样,如何使用方括号表示法将对象嵌套在另一个对象中?
This would be invalid. 这将是无效的。
If you define something like this: 如果您定义如下内容:
var test = {
option:1,
option:2,
option:3
};
How would you select each different option? 您将如何选择每个不同的选项? You couldn't. 你不能
An alternative would be: 一种替代方法是:
var example = {
items:[
{selector:".item", option:[10, 60]},
{selector:".otheritem", option:[20, 40]}
]
}
(Just to give you an idea.) (只是给您一个主意。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.