gpt4 book ai didi

angularjs csv下载到本地

转载 作者:行者123 更新时间:2023-12-02 08:44:59 24 4
gpt4 key购买 nike

如果用户单击按钮,我使用 $http Get with Angular 调用服务时,我让服务端返回 csv 格式。

So the return is like 1,2,3,4,5,6,7,8,9,10

为用户提供将其保存到本地计算机的最佳方式是什么?

最佳答案

有两种选择

1) 从您的服务器发送 csv。

2) 数据 URI。我想这就是你要的。这是一个例子

/**
* @param{string} content The contents of a file to download.
* @param{string} fileName The name to save the file as on the user's computer.
*/
function(content, fileName) {
var dataUrl = 'data:text/csv;utf-9,' + encodeURI(content);
var link = document.createElement('a');
angular.element(link)
.attr('href', dataUrl)
.attr('download', fileName) // Pretty much only works in chrome
link.click();
}

关于angularjs csv下载到本地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13167808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com