के साथ रिमोट डेटा प्राप्त करने का संयोजन हाय मैं चुनिंदा 2 का उपयोग करने के लिए देख रहा हूं और अब तक जो मैंने देखा है वह अच्छा दिखता है। मैं हालांकि एक काम करने की कोशिश कर रहा हूँ।चयन 2 - बहुउद्देश्यीय चयन और पूर्व डेटा
मैं अपने डेटा को एक जेएसएस फ़ाइल में AJAX कॉल के साथ प्राप्त करने के लिए देख रहा हूं - यह कैसे करना है इस पर उनकी वेबसाइट पर एक उदाहरण है लेकिन मैं एक prepopulates सूची रखने की कोशिश कर रहा हूं।
क्या मैं यह मतलब जब उदाहरण के लिए एक उपयोगकर्ता के लिए इस लिंक
http://ivaynberg.github.io/select2/#infinite
json फ़ाइल में पहले 10 फिल्मों सूचीबद्ध हैं तो वहाँ कुछ prechoices हैं पर एक फिल्म के लिए खोज पर क्लिक किया है।
किसी को भी सही dieection में मुझे बात कर सकते हैं
यहाँमेरी कोड अब तक
function movieFormatResult(movie) {
var markup = "<table class='movie-result'><tr>";
if (movie.posters !== undefined && movie.posters.thumbnail !== undefined) {
markup += "<td class='movie-image'><img src='" + movie.posters.thumbnail + "'/></td>";
}
markup += "<td class='movie-info'><div class='movie-title'>" + movie.title + "</div>";
if (movie.critics_consensus !== undefined) {
markup += "<div class='movie-synopsis'>" + movie.critics_consensus + "</div>";
}
else if (movie.synopsis !== undefined) {
markup += "<div class='movie-synopsis'>" + movie.synopsis + "</div>";
}
markup += "</td></tr></table>"
return markup;
}
function movieFormatSelection(movie) {
return movie.title;
}
$(document).ready(function() {
$("#e7").select2({
placeholder: "More",
minimumInputLength: 3,
ajax: {
url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json",
dataType: 'jsonp',
quietMillis: 100,
data: function (term, page) { // page is the one-based page number tracked by Select2
return {
q: term, //search term
page_limit: 10, // page size
page: page, // page number
apikey: "ju6z9mjyajq2djue3gbvv26t" // please do not use so this example keeps working
};
},
results: function (data, page) {
var more = (page * 10) < data.total; // whether or not there are more results available
// notice we return the value of more so Select2 knows if more results can be loaded
return {results: data.movies, more: more};
}
},
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
multiple: true,
escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
});
});
और html
<article class="row" id="infinite">
<div class="span12">
<p>
<input type="hidden" class="bigdrop" id="e7" style="width:200px"/>
</p>
</div>
</article>