Browse Source

Merge pull request #686 from spatialillusions/master

Added possibility to rename fields on a DataSet.get() or in a DataView.
v3_develop
Jos de Jong 9 years ago
parent
commit
4407b33916
3 changed files with 17 additions and 7 deletions
  1. +3
    -2
      docs/dataset.html
  2. +3
    -2
      docs/dataview.html
  3. +11
    -3
      lib/DataSet.js

+ 3
- 2
docs/dataset.html View File

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

+ 11
- 3
lib/DataSet.js View File

@ -663,9 +663,17 @@ DataSet.prototype._filterFields = function (item, fields) {
var filteredItem = {};
for (var field in item) {
if (item.hasOwnProperty(field) && (fields.indexOf(field) != -1)) {
filteredItem[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