Created
November 19, 2015 11:51
-
-
Save akorchev/9edce523fa4426c75f68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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