如何使用jqwidgets和angular生成特定的json?

如何使用jqwidgets和angular生成特定的json?,json,angular,angular6,jqwidget,Json,Angular,Angular6,Jqwidget,我正在尝试将数据表的数据导出到json文件中 该表是使用Angular6上的JQwidget创建的,数据来自API 但是,使用jqwidgets方法exportData('json');,只能制作一个json格式的表。 [{“id”:“1”,“name”:“test”}, {“id”:“2”,“name”:“toto”}] 我不知道如何将json的格式更改为这样: [“编号”:“2”, “1”:{“id”:“1”,“name”:“test”}, “2”:{“id”:“2”,“名称”:“toto”


我正在尝试将数据表的数据导出到json文件中
该表是使用Angular6上的JQwidget创建的,数据来自API

但是,使用jqwidgets方法exportData('json');,只能制作一个json格式的表。 [{“id”:“1”,“name”:“test”},
{“id”:“2”,“name”:“toto”}]

我不知道如何将json的格式更改为这样:
[“编号”:“2”,
“1”:{“id”:“1”,“name”:“test”},
“2”:{“id”:“2”,“名称”:“toto”}]


谢谢

我想做什么就做什么,事情是这样的:
首先,你不能用JqWidgets来做这件事
那么,我的解决方案是:
  • 我在nodejsapi中创建了字符串作为GET

    app.get('jsonfile', function (req, res) {
      res.header("Content-Disposition", "attachment;filename=\filename.txt\"");
      connection.query('select * from heroes', function(error, results, fields) {
        if (error) throw error;
        var JSONstring = "[";
          ...
          ...
          ...
        JSONstring = "]";
        res.end(JSONstring);
        console.log(JSONstring);
      });
    });
    
  • res.header('Content-Disposition','attachment;filename=\filename.txt\);如果要使此JSON字符串作为文件可向下移动,则我的解决方案必须使用此选项。
  • 我试图像其他人一样使用这个端点,但我遇到了这个问题:

    ERROR 
    Object { headers: {…}, status: 200, statusText: "OK", url: "http://localhost:3000/jsonfile", ok: false, name: "HttpErrorResponse", message: "Http failure during parsing for http://localhost:3000/jsonfile", error: {…} }
    
  • 因为它没有使用按钮单击和ts功能。
  • 我只是做了这个:

    <a href="http://localhost:3000/jsonfile" ><button>Creation JSON File</button></a>
    
    
    
    这对我很有效,但如果有更好的解决方案,我会很高兴知道

    谢谢大家的帮助

    <a href="http://localhost:3000/jsonfile" ><button>Creation JSON File</button></a>