Browse Source

Event listeners of `update` now receive an extra property `data`, containing the changed fields of the changed items.

v3_develop
jos 10 years ago
parent
commit
1ffaba543c
3 changed files with 22 additions and 10 deletions
  1. +11
    -3
      HISTORY.md
  2. +4
    -2
      docs/dataset.html
  3. +7
    -5
      lib/DataSet.js

+ 11
- 3
HISTORY.md View File

@ -2,7 +2,15 @@
http://visjs.org
## 2014-10-16, version 3.5.0
## not yet released, version 3.5.1
### DataSet
- Event listeners of `update` now receive an extra property `data`,
containing the changed fields of the changed items.
## 2014-09-16, version 3.5.0
### Network
@ -15,7 +23,7 @@ http://visjs.org
- Fixed dataAxis not showing large numbers correctly.
## 2014-10-12, version 3.4.2
## 2014-09-12, version 3.4.2
### Network
@ -25,7 +33,7 @@ http://visjs.org
- Fixed minor bug in positioning of fontFill of nodes with certain shapes.
## 2014-10-11, version 3.4.1
## 2014-09-11, version 3.4.1
### Network

+ 4
- 2
docs/dataset.html View File

@ -448,8 +448,10 @@ function (event, properties, senderId) {
In case of the events <code>add</code>,
<code>update</code>, and <code>remove</code>,
<code>properties</code> is always an object containing a property
items, which contains an array with the ids of the affected
items.
<code>items</code>, which contains an array with the ids of the affected
items. The <code>update</code> event has an extra field <code>data</code>
containing the original data of the updated items, i.e. the gives the
changed fields of the changed items.
</td>
</tr>
<tr>

+ 7
- 5
lib/DataSet.js View File

@ -204,10 +204,11 @@ DataSet.prototype.add = function (data, senderId) {
* @return {Array} updatedIds The ids of the added or updated items
*/
DataSet.prototype.update = function (data, senderId) {
var addedIds = [],
updatedIds = [],
me = this,
fieldId = me._fieldId;
var addedIds = [];
var updatedIds = [];
var updatedData = [];
var me = this;
var fieldId = me._fieldId;
var addOrUpdate = function (item) {
var id = item[fieldId];
@ -215,6 +216,7 @@ DataSet.prototype.update = function (data, senderId) {
// update item
id = me._updateItem(item);
updatedIds.push(id);
updatedData.push(item);
}
else {
// add new item
@ -254,7 +256,7 @@ DataSet.prototype.update = function (data, senderId) {
this._trigger('add', {items: addedIds}, senderId);
}
if (updatedIds.length) {
this._trigger('update', {items: updatedIds}, senderId);
this._trigger('update', {items: updatedIds, data: updatedData}, senderId);
}
return addedIds.concat(updatedIds);

Loading…
Cancel
Save