This is a migrated thread and some comments may be shown as answers.

Missing kendo.data.DataSource.prototype.set

0 Answers 109 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Lucian
Top achievements
Rank 1
Lucian asked on 14 Oct 2012, 08:40 PM
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

No answers yet. Maybe you can help?

Tags
Data Source
Asked by
Lucian
Top achievements
Rank 1
Share this question
or