Autor | Zpráva | ||
---|---|---|---|
darius1706 Profil |
#1 · Zasláno: 5. 9. 2013, 12:15:47
Zdravím, jsem úplný začátečník v použití select2 a návod, který je uveden moc nepřidá. Zkouším vůbec pochopit, jak to funguje a tak jsem zkusil příklad, který je uveden v dokumentaci, ale vůbec nic se neděje. Hledal jsem různé návody po webu, ale nebyl jsem úspěšný natolik, abych dospěl k funkční verzi. Zde je kód - je hodně poznamenám pokusy, takže co vše je tam v něm špatně? Děkuji !!! Radek
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" > <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <link href="http://ivaynberg.github.com/select2/select2-3.3.2/select2.css" rel="stylesheet" type="text/css" /> <script src="http://ivaynberg.github.com/select2/select2-3.3.2/select2.js"></script> <script> $(document).ready(function() { $("#e6").select2({ placeholder: "Search for a movie", minimumInputLength: 1, ajax: { // instead of writing the function to execute the request we use Select2's convenient helper url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json", dataType: 'jsonp', data: function (term, page) { return { q: term, // search term page_limit: 10, apikey: "ju6z9mjyajq2djue3gbvv26t" // please do not use so this example keeps working }; }, results: function (data, page) { // parse the results into the format expected by Select2. // since we are using custom formatting functions we do not need to alter remote JSON data return {results: data.movies}; } }, initSelection: function(element, callback) { // the input tag has a value attribute preloaded that points to a preselected movie's id // this function resolves that id attribute to an object that select2 can render // using its formatResult renderer - that way the movie name is shown preselected var id=$(element).val(); if (id!=="") { $.ajax("http://api.rottentomatoes.com/api/public/v1.0/movies/"+id+".json", { data: { apikey: "ju6z9mjyajq2djue3gbvv26t" }, dataType: "jsonp" }).done(function(data) { callback(data); }); } }, formatResult: movieFormatResult, // omitted for brevity, see the source of this page formatSelection: movieFormatSelection, // omitted for brevity, see the source of this page dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results }); }); </script> </head> <body> <p> <input type="hidden" class="bigdrop" id="e6" style="width:600px" value="16340"/> </p> </body> </html> |
||
Časová prodleva: 11 let
|
0