Missing kendo.data.DataSource.prototype.set

1 posts, 0 answers
  1. Lucian
    Lucian avatar
    1 posts
    Member since:
    Jul 2012

    Posted 14 Oct 2012 Link to this post

    Hi,

    I would like to validate this extension of kendo.data.DataSource:

    (function () {
        if (kendo.data.DataSource.prototype.set == undefined) {
            kendo.data.DataSource.prototype.set = function (id, model) {
                var idx, length, data = this._flatData(this._data);
     
                for (idx = 0, length = data.length; idx < length; idx++) {
                    // Found it?
                    if (data[idx].id == id) {
                        // Make sure it's model
                        if (!(model instanceof kendo.data.Model)) {
                            if (this.reader.model) {
                                model = new this.reader.model(model);
                            }
                            else {
                                model = new kendo.data.ObservableObject(model);
                            }
                        }
                        // Update it
                        data[idx] = model;
                        this._change();
                        break;
                    }
                }
                // Not found, add it
                if (idx == length) {
                    this.add(model);
                }
            }
        }
    })();

    Any thoughts or suggestions will be appreciated.

    Thx,
    Lucian
Back to Top