diff --git a/docs/dataset.html b/docs/dataset.html index 110afc0a..2c77c723 100644 --- a/docs/dataset.html +++ b/docs/dataset.html @@ -740,9 +740,10 @@ DataSet.map(callback [, options]); fields - String[ ] + String[ ] | Object.<String, String> - An array with field names. + An array with field names, or an object with current field name and + new field name that the field is returned as. By default, all properties of the items are emitted. When fields is defined, only the properties whose name is specified in fields will be included diff --git a/docs/dataview.html b/docs/dataview.html index 316da77a..eea7d2df 100644 --- a/docs/dataview.html +++ b/docs/dataview.html @@ -129,9 +129,10 @@ var data = new vis.DataView(dataset, options) fields - String[ ] + String[ ] | Object.<String, String> - An array with field names. + An array with field names, or an object with current field name and + new field name that the field is returned as. By default, all properties of the items are emitted. When fields is defined, only the properties whose name is specified in fields will be included diff --git a/lib/DataSet.js b/lib/DataSet.js index 9aa0238e..d002ac4f 100644 --- a/lib/DataSet.js +++ b/lib/DataSet.js @@ -663,15 +663,17 @@ DataSet.prototype._filterFields = function (item, fields) { var filteredItem = {}; - for (var field in item) { - if(Array.isArray(fields)){ - if (item.hasOwnProperty(field) && (fields.indexOf(field) != -1)) { - filteredItem[field] = item[field]; - } - }else{ - if (item.hasOwnProperty(field) && fields.hasOwnProperty(field)) { - filteredItem[fields[field]] = item[field]; - } + if(Array.isArray(fields)){ + for (var field in item) { + if (item.hasOwnProperty(field) && (fields.indexOf(field) != -1)) { + filteredItem[field] = item[field]; + } + } + }else{ + for (var field in item) { + if (item.hasOwnProperty(field) && fields.hasOwnProperty(field)) { + filteredItem[fields[field]] = item[field]; + } } }