我使用了一个功能,以CSV格式从Lists对象下载一些选择。我想对连接到Lists对象的整个数据源执行相同的操作,但是不确定如何缩放它以处理100,000行。在将列表数据下载为CSV的按钮上,我有:
var rows = widget.root.descendants.MainTableBody.children._values;
var csvdata = [];
csvdata.push([["Email"],["Last Login"],["Sku ID"],["Sku Name"],["Docs Added Recently"]]);
for (var i in rows) {
var t = [];
t.push(rows[i].children.EmailField.text);
t.push(rows[i].children.LastLoginField.text);
t.push(rows[i].children.SkuIdField.text);
t.push(rows[i].children.SkuNameField.text);
t.push(rows[i].children.DocsAddedField.text);
csvdata.push(t);
}
console.log(csvdata);
exportToCsv("LMexport",csvdata);
导出功能取自this answer。我基本上需要rows
var来覆盖整个表,但这是很多数据。
相关数据源的架构:
以下是用户界面中表格的外观:
答案 0 :(得分:0)
.reduce
将其转换为csv function exportCsv(){
var query = app.models.Employees.newQuery();
//query.filters.... use query used to populate the datasource
var records = query.run(); //[{},{},{}...]
var csv = records.reduce(function(str, rec){
var email = rec.Email;
var login = rec.LastLogin;
var skuId = rec.SkuId;
return str + '"' + [email,login,skuId].join('","') + '"\n'; // result: "email","login","skuId"\n
},'');
return csv;
}