Home > Web Front-end > H5 Tutorial > body text

Knockoutjs+select2 personnel search function code sharing

巴扎黑
Release: 2017-07-21 14:07:47
Original
2192 people have browsed it

 

HTML:

 

 

javascript:

$('.PersonEmail').select2({
               "separator": ",",
               "maximumSelectionSize": 10,
               "placeholder": "请选择用户",
               "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); //这里初始化
                   }
               }
           })

 

 

Currently it is only suitable for single selection. Multiple selection is still being configured and will be added after the test is passed.

The above is the detailed content of Knockoutjs+select2 personnel search function code sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template