Hi,
I have a huge json data source (over 50,000 + lines) loaded in memory from a static file.
It’s not important why I have it in a static file.
I have initialized select2 as:
$('#mySelect3').select2({
ajax: {},
dataAdapter: CustomData,
width: '100%'
});
My custom data look like:
function (ArrayData, Utils) {
function CustomData($element, options) {
CustomData.__super__.constructor.call(this, $element, options);
}
Utils.Extend(CustomData, ArrayData);
CustomData.prototype.query = function (params, callback) {
if (!("page" in params)) {
params.page = 1;
}
var data = {};
data.results = dataSelect.slice((params.page - 1) * pageSize, params.page * pageSize);
data.pagination = {};
data.pagination.more = params.page * pageSize < dataSelect.length;
callback(data);
};
});
Everythink works, but I have one big problem. I can’t set the value to select from jQuery. .
If I try like this:
$ ("#mySelect3").val(17003).trigger("change");
nothing will happen.
Please how do I implement select2 initialization, that can work with many options and can by set from jQuery?