我試圖記錄屬於一行的對象的位置。所以最後我需要一個全面的對象,它包含行和行內「com」的位置。這是我的代碼:(g
是一個全局對象)試圖使用括號表示法訪問深度值
g = {comPos:""}
$(".Com").draggable({
start: function(event, ui) {
var thisRow = $(this).closest("div[id^='step']");
g.thisRowID = thisRow.attr("id");
g.thisComID = $(this).attr("id");
console.log(g.thisComID); //returns the id value
},
stop: function(event, ui) {
var thisX = event.pageX;
var thisY = event.pageY;
var thisComPos = {
id: g.thisRowID,
x: thisX,
y: thisY
}
g.comPos[g.thisRowID][g.thisComID] = thisComPos; //undefined
}
});
這是一個被拋出的錯誤:
"TypeError: Cannot set property 'com1' of undefined"
使用括號標記我有不確定的回報方式。我究竟做錯了什麼?請告訴我,如果你需要更多的代碼,我已經粘貼了我認爲相關的部分。
我想我們需要看到g'的'定義。什麼是返回undefined,它是'g.comPos [g.thisRowID] [g.thisComID]'? – 2012-02-08 20:25:26
你可以包含「g」對象嗎? – 2012-02-08 20:27:22
@JulianD .-- g只包含一個空的「comPos」。 'g = {comPos:「」}' – dopatraman 2012-02-08 20:29:02