0
var db2arr = function() {
  var text = string.Empty;
  $(".tab_savedata .tmptextbox").empty();
  (dexie db class).tables.forEach( //access all tables
    function(table) {
      table.toArray(function(all) { //add table data tmptext
        //$(".tab_savedata .tmptextbox").append(
        text += (
          "\"" + table.name + "\":" +
          JSON.stringify(all) +
          ","
        );
      });
    }
  );
  return text.substring(0, -1);
}

$(".tab_savedata .export_data").on("click", function() {
  alert(db2arr());
}

When I execute this code, the "text" var stays empty. I had tried with commented part, but the element was not updated until the all function is finished.

This is the part of the chrome plugin, and supposed to print whole db in "dexie db class" class in json format.

I am sure that there is no other var named text. And I was running this at chrome.

https://github.com/Yukinyaa/KC3Kai/tree/master/src here is the whole project.

Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
YukiNyaa
  • 136
  • 1
  • 13
  • 3
    What is `dexie db class`? That's not valid Javascript. Nor is `string.Empty` (unless you defined that yourself elsewhere). – Mike Cluck Jan 27 '16 at 16:09
  • 1
    even if the text building was working, you shouldn't be building json yourself. build a normal array of `arr[table.name] = all`, then stringify the entire array after your forEach finishes. otherwise you're building up multiple independent json strings, which can/will cause problems later. – Marc B Jan 27 '16 at 16:10
  • Need more info (I am not inclined to dig into some project for a question myself) – Mark Schultheiss Jan 27 '16 at 16:12

0 Answers0