Search code examples
javascriptcode.orgapp-lab

How to properly read array from a data table on Code.Org AppLab?


I created a table called "morning" in AppLab, and one column stores data as an array (or list as it calls it). I'm able to properly add data to this array, but my problem is reading the data back (as I want to display it as a label/normal text on another page) If the numbers 1234 and 5678 are the values in the array, when I try to do

console.log(records[i].id + ': ' + records[i].buses);    

The second value (buses) is the name of the column I'm trying to read back, which will result in "," rather than "1234,5678" and I'm not really sure what to do. This is the code I have so far, any help would be greatly appreciated!

readRecords("morning", {}, function(records) {
  for (var i =0; i < records.length; i++) {
console.log((records[i]).id + ': ' + records[i].(buses[i]));
  }
 });

 var ts1Buses = ["1234"];
 var ts1Change;
onEvent("enterTS1", "click", function(event) {
  appendItem(ts1Buses, getText("textTS1"));
  updateRecord("morning", {id:1, buses:ts1Buses}, function(record, success) {
    setText("textTS1", "");
  });
});     

Solution

  • The console.log statement in your longer block of code doesn't look quite right. try console.log(records[i].id + ': ' + records[i].buses); instead. if that doesn't work, please post a link to your project so that others can try to find a fix by remixing and editing it.