我试图记录属于一行的对象的位置。所以最后我需要一个全面的对象,它包含行和行内“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