Skip to content

Instantly share code, notes, and snippets.

@akorchev
Created November 19, 2015 11:51
Show Gist options
  • Save akorchev/9edce523fa4426c75f68 to your computer and use it in GitHub Desktop.
Save akorchev/9edce523fa4426c75f68 to your computer and use it in GitHub Desktop.
(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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment