Browse Source

Updated code and docs for possibility to rename fields

v3_develop
Måns Beckman 9 years ago
parent
commit
f53012fdf9
3 changed files with 17 additions and 13 deletions
  1. +3
    -2
      docs/dataset.html
  2. +3
    -2
      docs/dataview.html
  3. +11
    -9
      lib/DataSet.js

+ 3
- 2
docs/dataset.html View File

@ -740,9 +740,10 @@ DataSet.map(callback [, options]);
<tr> <tr>
<td>fields</td> <td>fields</td>
<td>String[&nbsp;]</td>
<td>String[&nbsp;] | Object.&lt;String,&nbsp;String&gt;</td>
<td> <td>
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. By default, all properties of the items are emitted.
When <code>fields</code> is defined, only the properties When <code>fields</code> is defined, only the properties
whose name is specified in <code>fields</code> will be included whose name is specified in <code>fields</code> will be included

+ 3
- 2
docs/dataview.html View File

@ -129,9 +129,10 @@ var data = new vis.DataView(dataset, options)
<tr> <tr>
<td>fields</td> <td>fields</td>
<td>String[&nbsp;]</td>
<td>String[&nbsp;] | Object.&lt;String,&nbsp;String&gt;</td>
<td> <td>
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. By default, all properties of the items are emitted.
When <code>fields</code> is defined, only the properties When <code>fields</code> is defined, only the properties
whose name is specified in <code>fields</code> will be included whose name is specified in <code>fields</code> will be included

+ 11
- 9
lib/DataSet.js View File

@ -663,15 +663,17 @@ DataSet.prototype._filterFields = function (item, fields) {
var filteredItem = {}; 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];
}
} }
} }

Loading…
Cancel
Save