/    Sign up×
Community /Pin to ProfileBookmark

this.obj – same instance exists over multiple class instances

Hey there, having a very frustrating problem.

Here is my sheetCell class.

[code]
sheetCell = function(options) {
for(var x in options) this[x] = options[x];

if(this.headerNum != -1) {
var itm = this.parent.parent.header[this.headerNum];
this.objVal = document.createElement(“input”);
this.objVal.type = “hidden”;
this.objVal.name = this.parent.parent.name + “[“+this.parent.rowNum+”][“+itm.name+”]”;

switch(itm.type) {
case ‘text’:
this.obj = document.createElement(“input”);
this.obj.setAttribute(“data-role”,”none”);
this.obj.type = “text”;
this.objVal.value = this.obj.value = itm.value;
var self = this;
this.obj.onchange = function() {
self.objVal.value = self.obj.value;
}

break;
case ‘func’:
this.obj = itm.func(itm, this, “create”);
break;
}
}
};
sheetCell.prototype = {obj : null, objVal : null, parent : null, cellNum :-1, headerNum: -1,
value : function(val) {
if(typeof(val) == “undefined”)
return this.objVal.value;
else {
this.objVal.value = val;
}
},
display : function(val) {
if(typeof(val) == “undefined”)
return this.obj.value;
else
this.obj.value = val;
},
paint : function(cell) {
cell.appendChild(this.objVal);
cell.appendChild(this.obj);

if(this.parent.parent.header[this.headerNum].hidden) {
cell.style.display = “none”;
}
}
}
[/code]

For some reason, [b]this.obj[/b] and [b]this.objVal[/b] have the same instance in different Class instances.

I have tested to see if cellNum, headerNum and parent.rowNum have different values, and they do.

There is only one time where new sheetCell is being called, (It is being called in the code order shown below)

[code]
jqmSheet.prototype.proccessRows = function(data) {
for(var x in data) {

if(data[x].deleted == “0”) {
var aRow = this.addRow({noUpdate:true});
var aCell = null;
for(var y in data[x]) {
if(aCell = aRow.findCell(y)) {
aCell.value(data[x][y]);
aCell.display(data[x][y]);
}
}

if(this.updateRow) {
for(var x in this.header)
if(this.header[x].type == “func”)
this.header[x].func(this.header[x],aRow.findCell(this.header[x].name),”update”);

this.updateRow(aRow);

}
} else {
var h = document.createElement(“input”);
h.type = “hidden”;
h.name = this.name + “[“+x+”][deleted]”;
h.value = data[x].deleted;
h.setAttribute(“rowNum”,x);
this.invisEle.appendChild(h);
}
}

for(var x in this.row) {
for(var y in this.row[x].cell) {
alert(x + “::” + y + “::” + this.row[x].cell[y].objVal.name);
}
}
this.paint();
};

jqmSheet.prototype.addRow = function(options) {
if(typeof(options) == “undefined”) options = {};
++this.rowCount;

options[‘parent’] = this; options[‘rowNum’] = this.rowCount;
this.row[this.rowCount] = new this.sheetRow(options);

if(!options[‘noUpdate’])
if(this.updateRow)
this.updateRow(this.row[this.rowCount]);

return this.row[this.rowCount];
};

jqmSheet.prototype.sheetRow = function(options) {
for(var x in options) this[x] = options[x];

//on creation look through the header and add all the cells.
for(var x in this.parent.header) {
this.addCell({“headerNum”:x});
};
};

jqmSheet.prototype.sheetRow.prototype.addCell = function(options) {
//on creation
if(typeof(options) == “undefined”) options = {};
options[‘parent’] = this;
++this.cellCount;

options[‘cellNum’] = this.cellCount;
options[‘name’] = ”;

this.cell[this.cellCount] = new sheetCell(options);
return this.cell[this.cellCount];
}
[/code]

So, does anyone have any idea on how to fix this before I go insane? Hehe. Thank you very much

[b]Also, if anyone knows of an existing javascript class that lets you do data-entry I’d just use that instead.[/b]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @adamou spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...