{"action":"created","issue":{"url":"https://api.github.com/repos/select2/select2/issues/4671","repository_url":"https://api.github.com/repos/select2/select2","labels_url":"https://api.github.com/repos/select2/select2/issues/4671/labels{/name}","comments_url":"https://api.github.com/repos/select2/select2/issues/4671/comments","events_url":"https://api.github.com/repos/select2/select2/issues/4671/events","html_url":"https://github.com/select2/select2/issues/4671","id":187059531,"number":4671,"title":"Local data with ajax fallback","user":{"login":"krazyjakee","id":623463,"avatar_url":"https://avatars0.githubusercontent.com/u/623463?v=3","gravatar_id":"","url":"https://api.github.com/users/krazyjakee","html_url":"https://github.com/krazyjakee","followers_url":"https://api.github.com/users/krazyjakee/followers","following_url":"https://api.github.com/users/krazyjakee/following{/other_user}","gists_url":"https://api.github.com/users/krazyjakee/gists{/gist_id}","starred_url":"https://api.github.com/users/krazyjakee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krazyjakee/subscriptions","organizations_url":"https://api.github.com/users/krazyjakee/orgs","repos_url":"https://api.github.com/users/krazyjakee/repos","events_url":"https://api.github.com/users/krazyjakee/events{/privacy}","received_events_url":"https://api.github.com/users/krazyjakee/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-03T13:29:04Z","updated_at":"2017-05-15T15:10:29Z","closed_at":"2016-11-03T13:29:09Z","body":"Since this project has become an over-engineered clusterfuck rather than a simple input component, some of those who live in the real world want a simple solution to combine rendered options with an ajax fallback should the user start typing. I read others suggestions about dataAdapters and neither the docs, issues here or stackoverflow issues either explained them well or provided working examples. Some displaying the short, quick \"old\" way of doing things alongside the 500 lines of code needed to do the same thing in the \"new\" way. Essentially transferring any bloat from the library to the developer.\r\n\r\nAnyway, by putting the old \"query\" logic into the ajax transport, I was able to either return the rendered options or begin the ajax request.\r\n\r\n```javascript\r\nvar initials = [];\r\nvar combobox = $('.select2');\r\n\r\ncombobox.find('option').each(function(index, elem) {\r\n  elem = $(elem);\r\n initials.push({\r\n    id: elem.val(),\r\n    text: elem.text()\r\n  });\r\n});\r\n\r\nvar opts = {\r\n  tags: false,\r\n  multiple: true,\r\n  allowClear: true,\r\n  theme: \"bootstrap\",\r\n  ajax: {\r\n    url: url,\r\n    dataType: 'json',\r\n    type: 'get',\r\n    transport: function(params, success, error) {\r\n      if (params.data.term) {\r\n        if (params.data.term.length > 2) {\r\n          $.ajax({\r\n            url: params.url,\r\n            data: params.data,\r\n            success: success,\r\n            error: error\r\n          });\r\n        }\r\n      }\r\n      return success({\r\n        results: initials\r\n      });\r\n    },\r\n    data: function(params) {\r\n      var queryParameters;\r\n      return queryParameters = {\r\n        term: params.term\r\n      };\r\n    },\r\n    processResults: function(data) {\r\n      return {\r\n        results: $.map(data, function(item) {\r\n          return {\r\n            text: item.text,\r\n            id: item.value\r\n          };\r\n        }).concat(initials)\r\n      };\r\n    }\r\n  }\r\n};\r\n\r\ncombobox.select2(opts);\r\n```"},"comment":{"url":"https://api.github.com/repos/select2/select2/issues/comments/301505233","html_url":"https://github.com/select2/select2/issues/4671#issuecomment-301505233","issue_url":"https://api.github.com/repos/select2/select2/issues/4671","id":301505233,"user":{"login":"thinkh","id":5851088,"avatar_url":"https://avatars3.githubusercontent.com/u/5851088?v=3","gravatar_id":"","url":"https://api.github.com/users/thinkh","html_url":"https://github.com/thinkh","followers_url":"https://api.github.com/users/thinkh/followers","following_url":"https://api.github.com/users/thinkh/following{/other_user}","gists_url":"https://api.github.com/users/thinkh/gists{/gist_id}","starred_url":"https://api.github.com/users/thinkh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thinkh/subscriptions","organizations_url":"https://api.github.com/users/thinkh/orgs","repos_url":"https://api.github.com/users/thinkh/repos","events_url":"https://api.github.com/users/thinkh/events{/privacy}","received_events_url":"https://api.github.com/users/thinkh/received_events","type":"User","site_admin":false},"created_at":"2017-05-15T15:10:29Z","updated_at":"2017-05-15T15:10:29Z","body":"Thanks. Very helpful."}}
{"actor":{"display_login":"thinkh"}}