0
我試圖在這個對象中創建一個包含這個對象的變量的數組,但是我得到一個錯誤。 我使用這個錯誤嗎? THX的幫助在包含對象值的對象中創建一個數組
var data = {
p: [{content: "p",
text: "this is random text" },
{content: "p",
text: "this is a second random text"
}],
img: [{content: "image",
src: "data/img/1_1.png",
alt: "This a an image"},
{content: "image",
src: "data/img/1_2.png",
alt: "This is the second image"}],
title: {content: "title",
text: "Ceci est un titre"},
//This doesn't work
all: [this.title, this.p[0], this.img[0], this.p[1], this.img[1]]
}
//But this works
console.log(data.title);
console.log(data.p);
console.log(data.img);
您不能引用「正在建設中」對象的其他部分。 – Pointy
你的代碼中'this'的上下文是什麼?注意這一點。 – tfidelis
爲什麼在您可以輕鬆構建「全部」陣列時存儲冗餘信息? – Damon