मैं http://ivaynberg.github.io/select2/ से select2 jquery प्लगइन का उपयोग कर रहा हूं।init चयन चयन 2 jquery प्लगइन में नहीं जा रहा है
मैं निम्नलिखित कोड का उपयोग कर रहा हूं।
$(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',
quietMillis: 1000,
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) {
var id = 9942;//$(element).val();
alert('initSelection');
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
});
});
$(document).ready(function() {
$("#e6").on("select2-selecting", function (e) {
var v = 10;
alert("selecting val=" + e.val + " choice=" + JSON.stringify(e.choice));
var id = document.getElementById('<%= savebtn.ClientID %>');
id.value = e.val;
id.click();
});
});
समस्या: कुछ कारणों के लिए initSelection कहा जाता हो रही है नहीं है और इस वजह से, मैं के बाद पीठ भर में टेक्स्ट बॉक्स की अधिकतम मूल्य निर्धारित करने में सक्षम नहीं हूँ।
मैं http://ivaynberg.github.io/select2/ साइट से रिमोट डेटा उदाहरण लोड करने का उपयोग कर रहा हूं।
मैं initSelection के लिए documentation को देखा और यह कहते हैं, "यह फ़ंक्शन केवल जब वहाँ प्रारंभिक इनपुट संसाधित करने के लिए बुलाया जाएगा।", मुझे यकीन है कि वास्तव में क्या इसका मतलब है कि नहीं कर रहा हूँ।
क्या मैं कुछ गलत कर रहा हूं? कृपया मदद
धन्यवाद!!! यह – SharpCoder
काम करता है यह सही है। यहां तक कि यदि आप एक initSelection फ़ंक्शन प्रदान करते हैं, तो चुनें 2 इसे तब तक कॉल न करने का निर्णय लेता है जब तक कि आप "मान" attr प्रदान नहीं करते। इसलिए आपको या तो एक मूल्य एटीआर का उपयोग करने के लिए मजबूर होना पड़ता है, या एक प्रदान करता है और इसका उपयोग नहीं करता है। – fastmultiplication
समस्या यह है कि यह कई चयनित विकल्पों के लिए काम नहीं करेगा –