so I have created a small table row generator from JSON. When I started building it I hadn't put it in an object and it worked absolutley fine.
After, I made it so it could be abstract and just needes parameters passed to it. Then I put it in an object so that I could easily re use it for other sets of data. However, after putting it in an object I get the console message:
TypeError: this.getTableRow is not a function
But... it is a function:
getTableRow: function(data) {
row = "<tr>";
for (i in data) {
row += "<td>" + data[i] + "</td>";
}
row += "</tr>";
return row;
}
Here is the full script so you have it in context:
var dataCollector = {
baseDataURL: 'http://tourn.dev/data/',
displayDataTable: function(dataPath, tableIdentifier, dataKeys, dataOpts) {
$.getJSON(this.buildPath(dataPath, dataOpts), function (dataset) {
for (k in dataset) {
d = dataset[k];
data = [];
for (i in dataKeys) {
data[i] = d[dataKeys[i]];
}
;
$(tableIdentifier).append(this.getTableRow(data));
}
})
},
getDataURL: function() {
return this.baseDataURL;
},
buildPath: function(dataPath, dataOpts) {
path = this.getDataURL();
if (dataPath != null) {
path += dataPath;
}
if (dataOpts != null) {
if (dataOpts.constructor === Array) {
for (i in dataOpts) {
path += '/' + dataOpts[i];
}
} else {
path += '/' + dataOpts;
}
}
return path;
},
getTableRow: function(data) {
row = "<tr>";
for (i in data) {
row += "<td>" + data[i] + "</td>";
}
row += "</tr>";
return row;
}
};