[英]understanding jBox accessing properties in a array
I was just going through the code of jBox.js and came across the following snippet: 我只是浏览jBox.js的代码,并遇到了以下片段:
var appendImage = function(gallery, id, preload, open) {
if (jQuery('#jBox-image-' + gallery + '-' + id).length) return;
var image = jQuery('<div/>', {
id: 'jBox-image-' + gallery + '-' + id,
'class': 'jBox-image-container'
}).css({
backgroundImage: 'url(' + this.images[gallery][id].src + ')',
backgroundSize: this.options.imageSize,
opacity: (open ? 1 : 0),
zIndex: (preload ? 0 : this.imageZIndex++)
}).appendTo(this.content);
var text = jQuery('<div/>', {
id: 'jBox-image-label-' + gallery + '-' + id,
'class': 'jBox-image-label' + (open ? ' active' : '')
}).html(this.images[gallery][id].label).appendTo(this.imageLabel);
!open && !preload && image.animate({opacity: 1}, this.options.imageFade);
}.bind(this);
now my question is pertaining to a really complicated line of code that is trying to access a certain property in a array, i am talking about the below line of code: 现在我的问题与一个非常复杂的代码行有关,该行试图访问数组中的某个属性,我在谈论以下代码行:
this.images[gallery][id].src
what kind of an array is the above line really trying to access ? 上面的行真正尝试访问哪种数组? I have worked and accessed arrays like below:
我已经工作和访问如下数组:
var s = [{
a : 'name',
b : 'surname'
}];
val = s[0].a; // "name"
console.log(val);
But the syntax i have highlighted seems to have a extra bit of hierarchy. 但是我强调的语法似乎有点多余。 I am sorry, i am still a javascript novice and i am finding it hard to visualize how a array that gets accessed like below.
抱歉,我仍然是javascript新手,我发现很难形象化地访问数组,如下所示。
this.images[gallery][id].src
Would look like ? 会是什么样子? So well can somebody give me an example ?
那么有人可以给我一个例子吗? and explain ?
并解释?
Thank you. 谢谢。
gallery, id
might just be strings and you can use the following property accessor for those: gallery, id
可能只是字符串,您可以使用以下属性访问器:
var gallery = 'galleryx',
id = 'idx';
var images = { 'galleryx': { 'idx': 2 } };
console.log(images[gallery][id]) // === 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.