From f53012fdf9f74d041c066434c802b424e7a35a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=CC=8Ans=20Beckman?= Date: Wed, 4 Mar 2015 13:02:31 +0100 Subject: [PATCH] Updated code and docs for possibility to rename fields --- docs/dataset.html | 5 +++-- docs/dataview.html | 5 +++-- lib/DataSet.js | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) 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]; + } } }