Transform 数据转换
一个数据视图(DataSet.View)通过 Transform 来进行数据转换操作,其语法如下:
dv.transform({
type: connectorName,
...otherOptions,
});
举个例子:
const testCSV = `Expt,Run,Speed
1,1,850
1,2,740
1,3,900
1,4,1070`;
const dv = new DataSet.DataView().source(testCSV, {
type: 'csv',
});
console.log(dv.rows);
/*
* dv.rows:
* [
* {Expt: " 1", Run: "1", Speed: "850"}
* {Expt: " 1", Run: "2", Speed: "740"}
* {Expt: " 1", Run: "3", Speed: "900"}
* {Expt: " 1", Run: "4", Speed: "1070"}
* ]
*/
dv.transform({
type: 'filter',
callback(row) {
return row.Run !== '1';
},
});
console.log(dv.rows);
/*
* dv.rows:
* [
* {Expt: " 1", Run: "2", Speed: "740"}
* {Expt: " 1", Run: "3", Speed: "900"}
* {Expt: " 1", Run: "4", Speed: "1070"}
* ]
*/
上述代码中,数据视图实例 dv
使用 csv
类型的 Connector 载入了一段 CSV 文本,之后执行 filter
Transform,过滤了某些数据。
目前 DataSet 支持以下 Transform: