如何使用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来做这件事
那么,我的解决方案是:
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);
});
});
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: {…} }
<a href="http://localhost:3000/jsonfile" ><button>Creation JSON File</button></a>
这对我很有效,但如果有更好的解决方案,我会很高兴知道
谢谢大家的帮助
<a href="http://localhost:3000/jsonfile" ><button>Creation JSON File</button></a>