Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Fix #3 Support conversion Function between select2 and angularJS view mo... #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
if (opts.simple_tags) {
model = [];
angular.forEach(select2_data, function(value, index) {
model.push(value.id);
});
//modified by yjin to allow customized conversion function in options
//Original code here: model.push(value.id);
if(opts.convertToAngularFunc && (typeof (opts.convertToAngularFunc) === 'function')) {
opts.convertToAngularFunc.call(this, model, value);
}
else {
model.push(value.id);
}
});
} else {
model = select2_data;
}
Expand All @@ -64,7 +71,13 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
angular.forEach(
angular_data,
function(value, index) {
model.push({'id': value, 'text': value});
//modified by yjin to allow customized conversion function in options
//Original Code here: model.push({'id': value, 'text': value});
if(opts.convertToSelect2Func && (typeof (opts.convertToSelect2Func) === 'function')) {
opts.convertToSelect2Func.call(this, model, value);
} else {
model.push({'id': value, 'text': value});
}
});
} else {
model = angular_data;
Expand Down