Skip to content

Instantly share code, notes, and snippets.

@akorchev
Created November 19, 2015 11:51
Show Gist options
  • Select an option

  • Save akorchev/9edce523fa4426c75f68 to your computer and use it in GitHub Desktop.

Select an option

Save akorchev/9edce523fa4426c75f68 to your computer and use it in GitHub Desktop.

Revisions

  1. akorchev created this gist Nov 19, 2015.
    40 changes: 40 additions & 0 deletions ui5.datasource.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    (function($, undefined) {
    $.ui5 = $.ui5 || {};

    function DataSource(options) {
    var that = this;

    that.idMap = {};

    $.extend(that, options);
    }

    DataSource.prototype = {
    load: function() {
    var that = this;

    that.transport.read(function(result) {
    var idx, length, data, id = that.reader.id;

    that.data = data = that.reader.data(result);

    if (id) {
    for (idx = 0, length = data.length; idx < length; idx++) {
    that.idMap[id(data[idx])] = idx;
    }
    } else {
    for (idx = 0, length = data.length; idx < length; idx++) {
    that.idMap[idx] = idx;
    }
    }
    });
    },
    find: function(id) {
    return this.data[this.idMap[id]];
    }
    }

    $.extend($.ui5, {
    DataSource: DataSource
    });
    })(jQuery);