Knockoutjs + select2 personnel search, knockoutjsselect2
HTML:
<Select class = "form-control PersonEmail" id = "txtProjectManager" data-bind = "options: {text: ICVInfo. projectManager, value: ICVInfo. projectManager}, optionsText: 'text', optionsValue: 'value', value: ICVInfo. projectManager "> </select>
Javascript:
$ ('. PersonEmail'). select2 ({
"Separator ":",",
"MaximumSelectionSize": 10,
"Placeholder": "select a user ",
"AllowClear": false,
"MaximumInputLength": 100,
"MinimumResultsForSearch": "2 ",
"Tags": false,
TemplateResult: function (repo ){
Markup = repo. text;
Return markup;
},
EscapeMarkup: function (markup) {return markup ;},
TemplateSelection: function (repo ){
Return repo. text;
},
Ajax :{
@ * Url: '@ Url. Action ("SelectUser", "CommercialReminder")', dataType: 'json', data: function (params ){*@
Url: 'selectuser ',
DataType: 'json ',
Delay: 250,
Data: function (params ){
Return {
Q: params. term, // search term
Page: params. page
};
},
ProcessResults: function (data, params ){
Params. page = params. page | 1;
Return {
Results: data. items,
Pagination :{
More: (params. page * 30) <data. total_count
}
};
},
Cache: false,
Type: 'post'
},
InitSelection: function (element, callback ){
If (element. val ()! = Null ){
Var data = {id: element. val (), text: element. val ()};
// Alert (data. id );
Callback (data); // initialization here
}
}
})
Currently, it is only suitable for single choice. Multiple choices are still being configured, and will be available after the test is passed.