From 1a2d82dd088b7b606ff567a82d6f5ae158977212 Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 19 Jun 2014 16:49:09 +0200 Subject: [PATCH] Fixed DataSet.distinct requiring options.type to be configured --- src/DataSet.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/DataSet.js b/src/DataSet.js index 9ec557fc..996622d3 100644 --- a/src/DataSet.js +++ b/src/DataSet.js @@ -760,17 +760,18 @@ DataSet.prototype.min = function (field) { * The returned array is unordered. */ DataSet.prototype.distinct = function (field) { - var data = this._data, - values = [], - fieldType = this._options.type[field], - count = 0; + var data = this._data; + var values = []; + var fieldType = this._options.type && this._options.type[field] || null; + var count = 0; + var i; for (var prop in data) { if (data.hasOwnProperty(prop)) { var item = data[prop]; - var value = util.convert(item[field], fieldType); + var value = item[field]; var exists = false; - for (var i = 0; i < count; i++) { + for (i = 0; i < count; i++) { if (values[i] == value) { exists = true; break; @@ -783,6 +784,12 @@ DataSet.prototype.distinct = function (field) { } } + if (fieldType) { + for (i = 0; i < values.length; i++) { + values[i] = util.convert(values[i], fieldType); + } + } + return values; };